NCPC2017

见识了qt的分块求第k大,n*logn*sqrtn

可用set水,维护比1号小组优秀的组,然后set.size()得到答案。

#include
#include
#include
#include
#define maxl 100010

using namespace std;

int n,m;
struct state
{
	int pent,sum,ind;
	bool operator < (const state a) const
	{
		if((this->sum)==a.sum)
				return (this->pent)sum)>a.sum;
	}
	bool operator >(const state a) const
	{
		if((this->sum)==a.sum)
				return (this->pent)>a.pent;
		else
			return (this->sum)sum)==a.sum &&(this->pent)==a.pent; 
	}
}a[maxl];
set  s;

void prework()
{
	for(int i=1;i<=n;i++)
		a[i].pent=0,a[i].sum=0;
	s.clear();
}

void mainwork()
{
	state d;int t,p;
	set :: iterator it,it2;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&t,&p);
		d.pent=a[t].pent+p;d.sum=a[t].sum+1;d.ind=t;
		if(da[1]) && it!=s.begin())
		{
			it2=it;it--;
			s.erase(*it2);
		}
		if((*it)==a[1] || (*it)>a[1])
			s.clear();
		printf("%d\n",s.size()+1);
	}
}

int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		prework();
		mainwork();
	}
	return 0;
}


你可能感兴趣的:(分块思想)