1 条题解
-
2
模板题,代码如下
#include<bits/stdc++.h> #define lowbit(x) ((x) & - (x)) #define int long long using namespace std; const int N = 1e6 + 5; 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; } main(){ ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, Q, a, b = 0; cin >> n >> Q; for(int i = 1; i <= n; i++){ cin >> a; update(i, a - b); b = a; } while(Q--){ int opt, l, r, x; cin >> opt; if(opt == 1){ cin >> l >> r >> x; update(l, x); update(r + 1, -x); } else{ cin >> x; cout << sum(x) << endl; } } return 0; }
- 1
信息
- ID
- 320
- 时间
- 3000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 174
- 已通过
- 58
- 上传者