First, split the block. For the query, the block within the order of two points, for modification, direct violence, attention needs to maintain the original order, and constantly and within the block adjacent elements Exchange can be.
1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdio>5#include <cmath>6 using namespacestd;7 8 Const intN =300000;9 Const intM =650;Ten intA[n]; One intB[m][m]; A intN, M, U, PS, num; - - voidModifyintPosintval) the { - intcur = pos/PS; - if(Cur < num-1 ) - { + intp = lower_bound (B[cur], b[cur] + PS, A[pos])-B[cur]; - while(P +1< PS && B[cur][p +1] <val) + { AB[CUR][P] = b[cur][p +1]; atp++; - } - while(P-1>=0&& B[cur][p-1] >val) - { -B[CUR][P] = b[cur][p-1]; -p--; in } -B[CUR][P] =Val; to } +A[pos] =Val; - } the * voidUpdateintLintRintVintp) $ {Panax Notoginseng intcur = l/ps, ncur = r/ps, k =0; - if(cur! =ncur) the { + for(inti = cur +1; I <= ncur-1; i++ ) A { theK + = Lower_bound (B[i], b[i] + PS, v)-B[i]; + } - for(inti = l; I < (cur +1) * PS; i++ ) $ { $ if(A[i] < v) k++; - } - for(inti = ncur * PS; I <= R; i++ ) the { - if(A[i] < v) k++;Wuyi } the } - Else Wu { - for(inti = l; I <= R; i++ ) About { $ if(A[i] < v) k++; - } - } -Modify (P, U * 1ll * k/(R-l +1 ) ); A } + the intMain () - { $ while(SCANF ("%d%d%d", &n, &m, &u)! =EOF) the { thePS = -; the for(inti =0; I < n; i++ ) the { -scanf"%d", &a[i]); inB[i/ps][i% ps] =A[i]; the } thenum = (n + ps-1) /PS; About for(inti =0; I < num-1; i++ ) the { theSort (B[i], B[i] +PS); the } + while(m-- ) - { the intL, R, V, p;Bayiscanf"%d%d%d%d", &l, &r, &v, &p); theL--, R--, p--; the Update (L, R, V, p); - } - for(inti =0; I < n; i++ ) the { theprintf"%d\n", A[i]); the } the } - return 0; the}
UVA 12003 Block List