记录编号 174442 评测结果 AAAAAAAAAA
题目名称 贪婪大陆 最终得分 100
用户昵称 Gravatar<蒟蒻>我要喝豆奶 是否通过 通过
代码语言 C++ 运行时间 0.144 s
提交时间 2015-08-01 16:22:05 内存使用 1.05 MiB
显示代码纯文本
/**************************************************************
    Problem: cojs1008 Greedy Lands
    User: hznq60050(cobra)
    Solution: Segmet Tree(线段树) 
    Language: C++
    Result: ACCEPT
****************************************************************/
#include<cstdio>

using namespace std;

int lowbit(int x)
{
	return x&(-x);	
}

int n,m;
int c1[100010],c2[100010],tot;

int ask(int x,int y)
{
	int sum1=0;
	int sum2=0;
	while(x>0)
	{
		sum1+=c1[x];
		x-=lowbit(x);
	}
	while(y>0)
	{
		sum2+=c2[y];
		y-=lowbit(y);
	}
	return sum1+tot-sum2;
}

void insert(int x,int y)
{
	while(x<=n)
	{
		c1[x]++;
		x+=lowbit(x);
	}
	while(y<=n)
	{
		c2[y]++;
		y+=lowbit(y);
	}
	return ;
}

int main()
{
	freopen("greedisland.in","r",stdin);
	freopen("greedisland.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(a==1)
		{
			insert(c,b);
			tot++;
		}
		else
		{
			printf("%d\n",tot-ask(b-1,c));
		}
	}
	return 0;
}