Files
python/TangDou/AcWing/BIT/LOJ10115_BIT.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

37 lines
1015 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int const N = 50010;
int n, m;
// 树状数组模板
int c1[N], c2[N];
#define lowbit(x) (x & -x)
typedef long long LL;
void add(int c[], int x, int d) {
for (int i = x; i < N; i += lowbit(i)) c[i] += d;
}
LL sum(int c[], int x) {
LL res = 0;
for (int i = x; i; i -= lowbit(i)) res += c[i];
return res;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("LOJ10115.in", "r", stdin);
#endif
int k, l, r;
scanf("%d%d", &n, &m); // 第一行 n,m 表示道路总长为 n,共有 m 个操作;
// n下面没有使用过。为什么呢?其实是n的上限N有用!我们就没有用到n,代码模板中也去掉了n的
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &k, &l, &r);
if (k == 1)
add(c1, l, 1), add(c2, r, 1); // c1记录左括号的个数,c2记录右括号的个数
else
printf("%lld\n", sum(c1, r) - sum(c2, l - 1));
}
return 0;
}