QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136642#238. Distinct ValuesPlentyOfPenalty#100 ✓362ms23180kbC++201.8kb2023-08-09 09:37:382023-08-09 09:37:42

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 09:37:42]
  • 评测
  • 测评结果:100
  • 用时:362ms
  • 内存:23180kb
  • [2023-08-09 09:37:38]
  • 提交

answer

#include "bits/stdc++.h"
typedef unsigned un;
typedef long long ll;
const int MAXN = 200011;
int n,m;
struct Segment_Tree
{
	#define rt t[num]
	#define tl t[num<<1]
	#define tr t[num<<1|1]
	int t[MAXN<<2|1];
	void set(un pos,int val,un l=1,un r=n,un num=1)
	{
		if(l==r){rt=val;return;}
		un mid=(l+r)>>1;
		if(pos<=mid)set(pos,val,l,mid,num<<1);
		else set(pos,val,mid+1,r,num<<1|1);
		rt=tl+tr;
	}
	void modify(un pos,int val,un l=1,un r=n,un num=1)
	{
		if(l==r){rt+=val;return;}
		un mid=(l+r)>>1;
		if(pos<=mid)modify(pos,val,l,mid,num<<1);
		else modify(pos,val,mid+1,r,num<<1|1);
		rt=tl+tr;
	}
	int query(un l=1,un r=n,un num=1)
	{
		if(l==r)return l;
		un mid=(l+r)>>1;
		if(tl)return query(l,mid,num<<1);
		else return query(mid+1,r,num<<1|1);
	}
}sgt;
std::vector<int>ins[MAXN],del[MAXN];
std::multiset<int>S;
int a[MAXN];
int main()
{
	std::ios::sync_with_stdio(0),std::cin.tie(0);
	int task;std::cin>>task;
	while(task--)
	{
		//puts("New:");
		std::cin>>n>>m;
		while(m--)
		{
			int l,r;std::cin>>l>>r;
			ins[l].emplace_back(l),del[r+1].emplace_back(l);
		}
		for(int i=1;i<=n;++i)sgt.set(i,1);
		int it=0;
		for(int i=1;i<=n;++i)
		{
			// printf("i=%d:",i);
			for(auto p:ins[i])S.insert(p);//,printf("ins %d\n",p);
			for(auto p:del[i])S.erase(S.find(p));//,printf("del %d\n",p);
			if(S.empty())
			{
				while(it+1<i)sgt.modify(a[++it],1);
				//printf("fir,it=%d\n",it);
			}
			else 
			{
				//printf("it=%d,*s=%d\n",it,*S.begin());
				while(it+1<*S.begin())sgt.modify(a[++it],1);
				//printf("sec,it=%d\n",it);
			}
			a[i]=sgt.query();
			//printf("A[%d]=%d\n",i,a[i]);
			sgt.modify(a[i],-1);
		}
		for(auto p:del[n+1])S.erase(S.find(p));
		for(int i=1;i<=n;++i)printf("%d ",a[i]);
		puts("");
		for(int i=0;i<=n+1;++i)ins[i].clear(),del[i].clear();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 362ms
memory: 23180kb

input:

11116
10 2
5 5
5 6
10 1
7 10
10 1
2 6
10 1
2 5
10 1
6 7
10 2
8 9
7 10
10 2
1 4
6 10
10 4
8 8
10 10
3 6
1 5
10 3
8 8
10 10
8 10
10 4
6 10
1 5
2 6
1 2
10 3
4 4
4 8
4 8
10 4
1 5
1 2
5 5
2 4
10 4
2 5
9 10
6 7
2 4
10 1
5 6
10 4
10 10
8 10
2 5
10 10
10 1
1 2
10 4
7 8
5 6
7 9
10 10
10 4
3 7
6 6
8 10
3 4
10...

output:

1 1 1 1 1 2 1 1 1 1 
1 1 1 1 1 1 1 2 3 4 
1 1 2 3 4 5 1 1 1 1 
1 1 2 3 4 1 1 1 1 1 
1 1 1 1 1 1 2 1 1 1 
1 1 1 1 1 1 1 2 3 4 
1 2 3 4 1 1 2 3 4 5 
1 2 3 4 5 1 1 1 1 1 
1 1 1 1 1 1 1 1 2 3 
1 2 3 4 5 1 2 3 4 5 
1 1 1 1 2 3 4 5 1 1 
1 2 3 4 5 1 1 1 1 1 
1 1 2 3 4 1 2 1 1 2 
1 1 1 1 1 2 1 1 1 1 
1 1 2 ...

result:

ok 11116 lines