QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#502796 | #5159. Justice Served | Timeless123 | WA | 57ms | 8396kb | C++17 | 1.7kb | 2024-08-03 14:28:59 | 2024-08-03 14:29:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 9;
const int mod = 1e9 + 7;
#define eps 1e-5
#define inf 2e18
int n;
pair<int,int> p[N];
struct Node
{
int l,r,id;
bool operator<(const Node&u)const
{
if(r!=u.r) return r>u.r;
return l<u.l;
}
}a[N];
int cnt[N];
void solve()
{
cin>>n;
for(int i=1;i<=n;++i)
{
int x,y;cin>>x>>y;
a[i].l=x,a[i].r=x+y,a[i].id=i;
}
sort(a+1,a+1+n);
for(int i=1;i<=n;++i) p[i]={a[i].l,i};
sort(p+1,p+1+n);
int maxn=0;
for(int i=1;i<=n;++i)
{
//if(a[i].l >= a[i-1].l && a[i].r <= a[i-1].r) cnt[a[i].id]=max(cnt[a[i].id],cnt[a[i-1].id]+1),maxn=max(maxn,cnt[a[i].id]);
//else
if(a[i].r <= a[i-1].r)
{
int l = 1,r = n ,mid=0;
while(l < r)
{
int mid = (l + r) / 2;
if(p[mid].first > a[i].l) r = mid;
else l=mid+1;
}
int pos = p[l].second;
if(p[l].first > a[i].l) pos--;
if( pos >= i)
cnt[a[i].id] = max({cnt[a[pos].id] , maxn + 1,cnt[a[i].id]}) , maxn=max(cnt[a[i].id],maxn);
else
{
if(p[pos].first > a[i].l) pos--;
if(a[pos].r >= a[i].r && pos) cnt[a[i].id]=max(cnt[a[i].id],cnt[pos]+1),maxn=max(cnt[a[i].id],maxn);
}
}
}
for(int i=1;i<=n;++i) cout<<cnt[i]<<' ';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1; // cin>>_;
while (_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3700kb
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: 0ms
memory: 3648kb
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: 57ms
memory: 8396kb
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:
51094 25786 99792 20383 24330 1 19025 22937 88346 37721 39491 21169 55451 72518 60380 63911 2 24890 1 91630 2 45792 24237 1 51261 55452 93803 50868 12692 94208 65195 15162 71663 33121 92923 20838 81148 1 1958 98835 89779 1 95863 44290 89365 36811 2 1 1 8136 16043 87611 64902 90537 70227 36728 51108 ...
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: '51094 25786 99792 20383 24330 ...4296 91954 88099 2 57328 45193 '