版本比较
hhr
正文
增加 22 行删除 36 行
142 行未改动全部展开143144145146147147148149150151277 行未改动全部展开429430431432433433434435436437438439438439440441442443444445446447440441442443444449450451452453454455456445457446459460461462463464465447448449450451452467453454455469470456457458459475476477460461462463464465480481466467468469470471100 行未改动142 行未改动全部展开}a[2000010];
deque < node > q;
int tmp[2000010]; int tmp[2000010];
int main(){ cin >> n >> m; for(int i = 1;i <= n;i++){277 行未改动全部展开
# P3374```cpp#include <iostream>#include <vector>#define N 500005#define lowbit(x) ((x) & -(x))using namespace std;
int n,m,x,l,r;int tree[N];
class Binary_indexed_tree{private: int N; vector < int > tree,a;public: void init(vector < int > v,int n){ a = v; tree.resize(n + 5); for(int i = 1;i <= n;i++) update(i,a[i]); N = n;void update(int x,int d){ while(x <= N){ tree[x] += d; x += lowbit(x); }private: int lowbit(int x){return ((x) & (-x));}public: void update(int x,int d){ while(x <= N){ tree[x] += d; x += lowbit(x); }} }
int sum(int x){ int ans = 0; while(x > 0){ ans += tree[x]; x -= lowbit(x); } return ans;int sum(int x){ int ans = 0; while(x > 0){ ans += tree[x]; x -= lowbit(x); }}; return ans;}
vector < int > a(500005);
int main(){ ios::sync_with_stdio(false); cin.tie(nullptr),cout.tie(nullptr); cin >> n >> m; Binary_indexed_tree tree; for(int i = 1;i <= n;i++) cin >> a[i]; tree.init(a,500000); for(int i = 1;i <= n;i++){ cin >> x; update(i,x); } for(int i = 1;i <= m;i++){ cin >> x >> l >> r; if(x == 1) tree.update(l,r); else cout << tree.sum(r) - tree.sum(l - 1) << '\n'; if(x == 1) update(l,r); else cout << sum(r) - sum(l - 1) << '\n'; } return 0;}```100 行未改动