QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201437 | #5159. Justice Served | PhantomThreshold# | WA | 342ms | 45960kb | C++20 | 1.4kb | 2023-10-05 14:21:39 | 2023-10-05 14:21:40 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const int maxn = 410000;
int n;
struct node
{
int l,r,i;
}a[maxn];
inline bool cmp(const node &k1,const node &k2)
{
return k1.l==k2.l ? k1.r>k2.r : k1.l<k2.l;
}
map<int,int>mp; int mpn;
int t[maxn],tp;
struct segment
{
int seg[maxn<<2];
int loc,c;
void upd(const int x,const int l,const int r)
{
if(l==r)
{
seg[x]=max(seg[x],c);
return;
}
int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
if(loc<=mid) upd(lc,l,mid);
else upd(rc,mid+1,r);
seg[x]=max(seg[lc],seg[rc]);
}
int lx,rx;
int query(const int x,const int l,const int r)
{
if(rx<l||r<lx) return 0;
if(lx<=l&&r<=rx) return seg[x];
int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
return max(query(lc,l,mid),query(rc,mid+1,r));
}
}seg;
int ans[maxn];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
a[i].i=i;
cin>>a[i].l>>a[i].r;
t[++tp]=a[i].l;
t[++tp]=a[i].r;
}
sort(t+1,t+tp+1);
tp=unique(t+1,t+tp+1)-t-1;
for(int i=1;i<=tp;i++) mp[t[i]]=i;
mpn=tp;
for(int i=1;i<=n;i++) a[i].l=mp[a[i].l], a[i].r=mp[a[i].r];
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
{
seg.lx=a[i].r,seg.rx=mpn;
int qc= seg.query(1,1,mpn);
ans[a[i].i]=qc;
seg.loc=a[i].r,seg.c=qc+1;
seg.upd(1,1,mpn);
}
for(int i=1;i<=n;i++) cout<<ans[i]<<" \n"[i==n];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5724kb
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: 5704kb
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: 342ms
memory: 45960kb
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:
51067 25775 6 14 12 14 19015 9 88306 37703 9 21158 55423 15 13 16 12 24879 15 7 8 45768 24224 14 11 55424 9 7 12683 15 65167 14 1 33107 19 20827 81112 10 1963 98792 89739 13 95821 44266 89326 16 8 16 4 8131 16033 8 9 90497 70197 36711 14 15 46836 39837 38641 13 53674 7 16 4 15 18 12 83782 15935 9 4 ...
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: '51067 25775 6 14 12 14 19015 9...14 14 84259 91914 88059 14 12 8'