0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-05 14:18:47 +00:00
OI-codes/Luogu/problem/P4939/P4939.cpp
2021-01-02 15:30:52 +08:00

40 lines
644 B
C++

#include <bits/stdc++.h>
using namespace std;
int n, m, op, x, y, t[10000005];
int lowbit(int k) {
return k & -k;
}
void add(int x, int v) {
for (int i = x; i <= n + 1; i += lowbit(i)) {
t[i] += v;
}
}
int sum(int x) {
int ans = 0;
for (int i = x; i > 0; i -= lowbit(i)) {
ans += t[i];
}
return ans;
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> op >> x;
if (op == 0) {
cin >> y;
add(x, 1);
add(y + 1, -1);
}
else if (op == 1) {
cout << sum(x) << endl;
}
}
return 0;
}