QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#186773#5159. Justice ServedForever_Young#WA 140ms11816kbC++231.8kb2023-09-24 11:35:422023-09-24 11:35:42

Judging History

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

  • [2023-09-24 11:35:42]
  • 评测
  • 测评结果:WA
  • 用时:140ms
  • 内存:11816kb
  • [2023-09-24 11:35:42]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;++i)
#define per(i,n) for(int i=n;i>=1;--i)
#define pb push_back
#define mp make_pair
#define N 210000
int n;
struct node
{
	int l,r,id;
	friend bool operator <(node x,node y)
	{
		if (x.l!=y.l)return x.l<y.l;
		return x.r>y.r;
	}
}a[2*N];
int ans[N];
int st[2*N];
void build(int t,int l,int r)
{
	st[t]=-1;
	if (l==r)return;
	int mid=(l+r)/2;
	build(2*t,l,mid);
	build(2*t+1,mid+1,r);
}
int getmax(int t,int l,int r,int a,int b)
{
	if (a<=l && r<=b)return st[t];
	int mid=(l+r)/2;
	int ret=-1;
	if (a<=mid)ret=max(ret,getmax(2*t,l,mid,a,b));
	if (b>mid)ret=max(ret,getmax(2*t+1,mid+1,r,a,b));
	return ret;
}
void insert(int t,int l,int r,int k,int p)
{
	if (l==r)
	{
		st[t]=max(st[t],p);
		return;
	}
	int mid=(l+r)/2;
	if (k<=mid)insert(2*t,l,mid,k,p);
	else insert(2*t+1,mid+1,r,k,p);
	st[t]=max(st[2*t],st[2*t+1]);
}
int main()
{
	cin>>n;
	static vector<int> save; save.clear();
	rep(i,n)
	{
		a[i].id=i;
		int x,y; scanf("%d%d",&x,&y);
		a[i].l=x; a[i].r=x+y; save.pb(a[i].l); save.pb(a[i].r);
	}
	sort(save.begin(),save.end());
	save.resize(unique(save.begin(),save.end())-save.begin());
	rep(i,n)a[i].l=lower_bound(save.begin(),save.end(),a[i].l)-save.begin()+1;
	rep(i,n)a[i].r=lower_bound(save.begin(),save.end(),a[i].r)-save.begin()+1;
	sort(a+1,a+n+1);
	int m=save.size();
	build(1,0,m);
	rep(i,n)
	{
		int f=getmax(1,0,m,a[i].r,m)+1;
		insert(1,0,m,a[i].r,f);
		
		//cout<<a[i].id<<" "<<a[i].l<<" "<<a[i].r<<" "<<f<<endl;
		ans[a[i].id]=f;
	}
	rep(i,n)printf("%d%c",ans[i],i==n?'\n':' ');
	return 0;
}

详细

Test #1:

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

input:

4
2 8
1 7
4 5
5 2

output:

0 0 1 2

result:

ok single line: '0 0 1 2'

Test #2:

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

input:

5
2 4
3 3
2 2
4 2
4 1

output:

0 1 1 2 3

result:

ok single line: '0 1 1 2 3'

Test #3:

score: -100
Wrong Answer
time: 140ms
memory: 11816kb

input:

200000
75760147 173015388
62879760 211229046
6728658 106668560
29476341 129401393
30531505 130450085
39792769 139780734
59486082 221617335
12447225 112582555
94207716 117434450
68962063 193352291
13519090 113644734
60611935 218232526
77901558 166662816
40316254 140281744
39094390 138994435
49921965 ...

output:

74100 62524 28886 31952 28886 59966 52832 -1 111339 12518 -1 53960 78456 35586 34518 28886 12518 12518 13167 12518 12083 68801 55573 -1 12518 78457 -1 12518 49063 12518 88200 -1 12518 -1 12518 12518 104145 12518 42914 121825 112772 31313 118854 67299 112359 13167 -1 38120 12518 3 51263 12518 4 11353...

result:

wrong answer 1st lines differ - expected: '51062 25770 5 10 10 12 19010 7...59 9 12 84254 91909 88054 9 7 7', found: '74100 62524 28886 31952 28886 ...612 107292 114947 111092 0 4 -1'