Description have aaaNanumberof thenumberGroupa,have aNaLetternumber,everyaLetternumberis areturnback[ l i , r i ]of theand the There are two actions 1 x y: Modify the value of the X element of the array to y2 m N: Ask the [m,n] function and N,q ≤ ten 5 Solution we can consider chunking, dividing the function into n ?? √ Block , preprocessing each block of functions and the number of each count in each function, and then use a tree array to find the array and modify the answer according to the number of X occurrences in each block function, the tree array of single point modification, when asked casually engage in code
#include <bits/stdc++.h>using namespace STD;typedef Long LongLL;Const intN =100010;intN, Q, A[n], l[n], r[n], cnt[ the][n], num[ the][n]; LL C[n], sum[n];inline intReadint&t) {intf =1;CharC while(c = GetChar (), C <' 0 '|| C >' 9 ')if(c = ='-') F =-1; T = C-' 0 '; while(c = GetChar (), C >=' 0 '&& C <=' 9 ') T = T *Ten+ C-' 0 '; T *= F;}voidAddintIintx) { for(; I <= n; i + = i & i) c[i] + = x;}voidChangeintIintx) {Add (I, x-a[i]); A[i] = x;} LL Ask (inti) {LL t =0; for(; i; i-= i & i) T + = c[i];returnt;}intMain () {read (n);intBL = (int)sqrt(n +0.5);intS = N/bl + ((n% bl)?1:0); for(inti =1; I <= N; ++i) read (A[i]); for(inti =1; I <= N; ++i) Add (i, a[i]); for(inti =0; I < n; ++i) {read (L[i]), read (R[i]); ++cnt[i/bl][l[i]]; --cnt[i/bl][r[i] +1]; } for(inti =0; i < S; ++i) for(intj =1; J <= N; ++J) {Num[i][j] = Cnt[i][j] + num[i][j-1]; Sum[i] + =1uLL * Num[i][j] * A[J]; } read (q); while(q--) {intOP, L, R; Read (OP), read (L), read (R);if(OP = =1) { for(inti =0; i < S; ++i) Sum[i] + =1uLL * Num[i][l] * (R-a[l]); Change (l, R); }Else{--l,--r; LL ans =0;intx = l/bl, y = r/bl;if(x = = y) for(inti = l; I <= R; ++i) ans + = ask (R[i])-Ask (L[i]-1);Else{x = (l% BL? x +1: x), y = (R +1)% BL? Y-1: y; for(inti = x; I <= y; ++i) ans + = sum[i]; while(l% bl) ans + = ask (R[l])-Ask (l[l++]-1); while(R +1)% bl) ans + = ask (R[r])-Ask (l[r--]-1); }printf("%llu\n", ans); } }return 0;}
Codechef Chef and Churu