QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#154498#5159. Justice Servedacm202226010311RE 2ms7624kbC++141.1kb2023-08-31 18:33:482023-08-31 18:33:48

Judging History

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

  • [2023-08-31 18:33:48]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:7624kb
  • [2023-08-31 18:33:48]
  • 提交

answer

#include<iostream>
#include<algorithm>
using namespace std;
int d[1000000];
int x[1000000];
int len;
struct node
{
	int l,r;
	int id;
}qur[100005];
bool cmp(node a,node b)
{
	return a.l==b.l?a.r>b.r:a.l<b.l;
}
int lobwit(int y)
{
	return y&(-y);
}
void built()
{
	for(int i=1;i<=len;i++)
	d[i]=-1;
}
int quiry(int y )
{
	int ans=-1;
	while(y<=len)
	{
		ans=max(ans,d[y]);
		y+=lobwit(y);
	}
	return ans;
}
void unite(int y,int v)
{
	while(y>=1)
	{
		d[y]=max(v,d[y]);
		y-=lobwit(y);
	}
}
int main()
{   ios::sync_with_stdio(0);
    cin.tie(0); 
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{   int a,b;
	   cin>>a>>b;
		qur[i].l=a;
		qur[i].r=a+b;
		qur[i].id=i;
		x[i*2]=a;
		x[i*2+1]=a+b;
	}
	sort(qur,qur+n,cmp);
	sort(x,x+2*n);
     len=unique(x,x+2*n)-x;
	for(int i=0;i<n;i++)
	{
		qur[i].l=lower_bound(x,x+len,qur[i].l )-x+1;
		qur[i].r=lower_bound(x,x+len,qur[i].r )-x+1;
	}
	built();
	int ans[n];
	for(int i=0;i<n;i++)
	{   int res=quiry(qur[i].r)+1;
		ans[qur[i].id]=res;
		unite(qur[i].r,res);
		
	}
	for(int i=0;i<n;i++)
	cout<<ans[i]<<" ";
	
}

詳細信息

Test #1:

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

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: 2ms
memory: 7624kb

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
Runtime Error

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:


result: