QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#154498 | #5159. Justice Served | acm202226010311 | RE | 2ms | 7624kb | C++14 | 1.1kb | 2023-08-31 18:33:48 | 2023-08-31 18:33:48 |
Judging History
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]<<" ";
}
Details
Tip: Click on the bar to expand more detailed information
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 ...