树状数组 #include<iostream> #include<cstring> #include<algorithm> using namespace std; int a[500005], b[500005]; int n, m, tag; int ask(int x){ int res = 0; for(; x; x -= x & -x) res += b[x]; return res; } int add(int x, int y){ for(; x <= n; x += x & -x) b[x] += y; ...