0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-26 18:12:05 +00:00
OI-codes/Luogu/P4939/P4939.cpp

39 lines
636 B
C++
Raw Normal View History

2020-12-13 13:34:42 +00:00
#include <bits/stdc++.h>
using namespace std;
2020-12-13 13:41:13 +00:00
int n, m, op, x, y, t[10000005];
2020-12-13 13:34:42 +00:00
2020-12-13 13:41:13 +00:00
int lowbit(int k) {
return k & -k;
2020-12-13 13:34:42 +00:00
}
2020-12-13 13:41:13 +00:00
void add(int x, int v) {
for (int i = x; i <= n + 1; i += lowbit(i)) {
t[i] += v;
2020-12-13 13:34:42 +00:00
}
}
2020-12-13 13:41:13 +00:00
int sum(int x) {
int ans = 0;
for (int i = x; i > 0; i -= lowbit(i)) {
ans += t[i];
2020-12-13 13:34:42 +00:00
}
2020-12-13 13:41:13 +00:00
return ans;
2020-12-13 13:34:42 +00:00
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> op >> x;
if (op == 0) {
cin >> y;
2020-12-13 13:41:13 +00:00
add(x, 1);
add(y + 1, -1);
2021-11-19 09:01:13 +00:00
} else if (op == 1) {
2020-12-13 13:41:13 +00:00
cout << sum(x) << endl;
2020-12-13 13:34:42 +00:00
}
}
return 0;
}