QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282264#1173. Knowledge Is...Aurora_WindWA 1ms6008kbC++14792b2023-12-11 17:04:092023-12-11 17:04:10

Judging History

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

  • [2023-12-11 17:04:10]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6008kb
  • [2023-12-11 17:04:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,j=1,p=1,l,r,mid,res,ans[500005],cnt;
struct node{int l,r,id;}a[500005],b[500005];
inline bool cmp1(node a,node b){return a.r<b.r;}
inline bool cmp2(node a,node b){return a.l<b.l;}
inline bool check(int x)
{
	for(int i=1;i<=x;++i) if(a[i].r>b[n-x+i].l) return false;
	return true;
}
int main()
{
	scanf("%d%d",&n,&m),l=1,r=n/2;
	for(int i=1;i<=n;++i) scanf("%d%d",&a[i].l,&a[i].r),a[i].id=i,b[i]=a[i];
	sort(a+1,a+n+1,cmp1),sort(b+1,b+n+1,cmp2);
	while(l<=r)
	{
		mid=l+r>>1;
		if(check(mid)) l=mid+1,res=mid;
		else r=mid-1;
	}
	for(int i=1;i<=res;++i)
	{
		ans[a[i].id]=ans[b[n-res+i].id]=++cnt;
	}
	for(int i=1;i<=n;++i)
	{
		if(!ans[i]) ans[i]=++cnt;
		printf("%d ",(ans[i]<=m)?ans[i]:0);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5964kb

input:

7 5
9 10
7 9
3 4
9 10
2 6
8 9
5 8

output:

2 4 1 3 2 1 3 

result:

ok answer = 7

Test #2:

score: 0
Accepted
time: 1ms
memory: 6008kb

input:

2 2
1 2
3 4

output:

1 1 

result:

ok answer = 2

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5832kb

input:

2 1
1 2
2 3

output:

1 1 

result:

wrong answer Interval intersecting