QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136732#238. Distinct ValueskiwiHM#100 ✓102ms5468kbC++141.4kb2023-08-09 10:42:292023-08-09 10:42:31

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 10:42:31]
  • 评测
  • 测评结果:100
  • 用时:102ms
  • 内存:5468kb
  • [2023-08-09 10:42:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int nu[400010];
int v[100010],a[100010];
inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
inline int find(int x,int l,int r)
{
	nu[x]++;
	if(l==r) return l;
	int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
	if(nu[lc]!=(mid-l+1)) return find(lc,l,mid);
	return find(rc,mid+1,r); 
}
inline void eras(int x,int l,int r,int pos)
{
	nu[x]--;
	if(l==r) return ;
	int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
	if(pos<=mid) eras(lc,l,mid,pos);
	else eras(rc,mid+1,r,pos);
}
inline void clear(int x,int l,int r)
{
	nu[x]=0;
	if(l==r) return ;
	int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
	clear(lc,l,mid),clear(rc,mid+1,r);
}
int main()
{
	int T=read();
	while(T)
	{
		T--;
		int n=read(),m=read();
		clear(1,1,n);
		for(int i=1;i<=n;i++) v[i]=0;
		for(int i=1;i<=m;i++)
		{
			int l=read(),r=read();
			v[l]=max(v[l],r);
		}
		for(int i=1,pos=0;i<=n;i++)
		{
			if(!v[i])
			{
				if(pos<i) a[i]=1;
				else eras(1,1,n,a[i]);
			}
			else
			{
				if(v[i]<=pos) eras(1,1,n,a[i]);
				else
				{
					pos=max(pos,i-1);
					for(int j=pos+1;j<=v[i];j++)
						a[j]=find(1,1,n);
					eras(1,1,n,a[i]),pos=v[i];
				}
			}
		}
		for(int i=1;i<=n;i++) printf("%d ",a[i]);
		puts("");
	}
}







Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 102ms
memory: 5468kb

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