#include 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; }