跳到正文

个人记录

P2184

ExCh_dd2014_Gcdunk约 1 分钟
原文

这是 2025年12月20日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

收录
2025年12月20日
更新
2026年4月4日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1
C++
#include <bits/stdc++.h>
using namespace std;
int t[100005][2], n, m;
#define lowbit(x) x & (-x)
void update(int pos, int x)
{
    while(pos <= n)
    {
        t[pos][x]++;
        pos += lowbit(pos);
    }
}
int sum(int pos, int x)
{
    int ret = 0;
    while(pos)
    {
        ret += t[pos][x];
        pos -= lowbit(pos);
    }
    return ret;
}
signed main()
{
    cin >> n >> m;
    while(m--)
    {
        int opt, l, r;
        cin >> opt >> l >> r;
        if(opt == 1)
            update(l, 0), update(r, 1);
        else 
            cout << sum(r, 0) - sum(l - 1, 1) << '\n';
    }
}