0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:28:48 +00:00

#10115. 「一本通 4.1 例 3」校门外的树

https://loj.ac/s/1025566
This commit is contained in:
Baoshuo Ren 2021-01-03 08:16:25 +08:00 committed by Baoshuo Ren
parent 1527997627
commit c0fb0094dc
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

55
LibreOJ/10115/10115.cpp Normal file
View File

@ -0,0 +1,55 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, op, l, r, c1[1000001], c2[1000001];
int lowbit(int x) {
return x & (-x);
}
inline void update1(int x, int v) {
while (x <= n) {
c1[x] += v;
x += lowbit(x);
}
}
inline void update2(int x, int v) {
while (x <= n) {
c2[x] += v;
x += lowbit(x);
}
}
int sum1(int x) {
int p = 0;
while (x > 0) {
p += c1[x];
x -= lowbit(x);
}
return p;
}
int sum2(int x) {
int p = 0;
while (x > 0) {
p += c2[x];
x -= lowbit(x);
}
return p;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> op >> l >> r;
if (op == 1) {
update1(l, 1), update2(r, 1);
}
if (op == 2) {
cout << sum1(r) - sum2(l - 1) << endl;
}
}
return 0;
}