正文
增加 22 行删除 36 行
142 行未改动全部展开143144145146147148149150151277 行未改动全部展开429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485100 行未改动142 行未改动全部展开}a[2000010];deque < node > q;int tmp[2000010];int main(){cin >> n >> m;for(int i = 1;i <= n;i++){277 行未改动全部展开# P3374```cpp#include <iostream>#include <vector>using namespace std;int n,m,x,l,r;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;}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;}};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 <= m;i++){cin >> x >> l >> r;if(x == 1) tree.update(l,r);else cout << tree.sum(r) - tree.sum(l - 1) << '\n';}return 0;}```100 行未改动142 行未改动全部展开143144145146147148149150151277 行未改动全部展开429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471100 行未改动142 行未改动全部展开}a[2000010];deque < node > q;int tmp[2000010];int main(){cin >> n >> m;for(int i = 1;i <= n;i++){277 行未改动全部展开# P3374```cpp#include <iostream>#define N 500005#define lowbit(x) ((x) & -(x))using namespace std;int n,m,x,l,r;int tree[N];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 main(){ios::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);cin >> n >> m;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) update(l,r);else cout << sum(r) - sum(l - 1) << '\n';}return 0;}```100 行未改动