P2184
ExCh_dd2014_Gcdunk
·
·
个人记录
#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';
}
}