0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

242. 一个简单的整数问题

https://www.acwing.com/problem/content/submission/code_detail/13302315/
This commit is contained in:
Baoshuo Ren 2022-04-11 13:30:40 +08:00
parent f587de10cf
commit 78c3fc5579
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

49
AcWing/242/242.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, m, l, r, d, x, a[N], c[N];
char op;
inline int lowbit(int x) {
return x & -x;
}
void add(int x, int y) {
for (; x <= n; x += lowbit(x)) c[x] += y;
}
int sum(int x) {
int ans = 0;
for (; x; x -= lowbit(x)) ans += c[x];
return ans;
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
while (m--) {
cin >> op;
if (op == 'C') {
cin >> l >> r >> d;
add(l, d);
add(r + 1, -d);
} else { // op == 'Q'
cin >> x;
cout << a[x] + sum(x) << endl;
}
}
return 0;
}