QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201526 | #5159. Justice Served | Vengeful_Spirit# | WA | 121ms | 8204kb | C++14 | 1.3kb | 2023-10-05 14:58:22 | 2023-10-05 14:58:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
struct seg{
int l,r;
}t[N];
int n,nn;
int c[2*N];
void modify(int x,int res){
// cout<<"modi "<<x<<' '<<res<<endl;
for(;x;x-=x&(-x)){
c[x]=max(c[x],res);
// cout<<x<<endl;
}
}
int query(int x){
// cout<<"query "<<x<<endl;
int res=0;
for(;x<=nn;x+=x&(-x)){
res=max(res,c[x]);
// cout<<x<<" "<<res<<endl;
}
return res;
}
int res[N];
int main(){
scanf("%d",&n);
vector<int>s;
for(int i=1;i<=n;i++){
int l,r;
scanf("%d%d",&l,&r);
r=l+r;
s.push_back(l);
s.push_back(r);
t[i]={l,r};
}
sort(s.begin(),s.end());
s.erase(unique(s.begin(),s.end()),s.end());
nn=s.size()+1;
for(int i=1;i<=n;i++){
t[i].l=lower_bound(s.begin(),s.end(),t[i].l)-s.begin()+1;
t[i].r=lower_bound(s.begin(),s.end(),t[i].r)-s.begin()+1;
// cout<<t[i].l<<" "<<t[i].r<<endl;
}
sort(t+1,t+1+n,[&](seg a,seg b){
if(a.l!=b.l)return a.l<b.l;
else return a.r>b.r;
});
for(int i=1;i<=n;i++){
res[i]=query(t[i].r);
modify(t[i].r,res[i]+1);
}
for(int i=1;i<=n;i++){
printf("%d ",res[i]);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5900kb
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: 5872kb
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: 121ms
memory: 8204kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
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: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 99902 99903 99904 99905 99906 '