QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#122824 | #6192. Interval Problem | Wolam | RE | 1ms | 15772kb | C++14 | 987b | 2023-07-11 11:45:13 | 2023-07-11 11:45:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,l[20005],r[200005];
int p[400005],sum[400005];
int ans[200005];
int h[400005],g[400005],f[400005];
void sol()
{
memset(p,0x3f,sizeof(p));
memset(sum,0,sizeof(sum));
for(int i=1;i<=n;i++)
{
p[r[i]]=l[i];
sum[r[i]]++;
}
for(int i=1;i<=n+n;i++)
sum[i]+=sum[i-1];
for(int i=n+n;i>=1;i--)
p[i]=min(p[i],p[i+1]);
for(int i=1;i<=n+n;i++)
{
if(p[i]>=i)
{
g[i]=i;
f[i]=h[i]=0;
}
else
{
g[i]=g[p[i]];
h[i]=h[p[i]]+1;
f[i]=sum[i-1]+f[p[i]];
}
}
for(int i=1;i<=n;i++)
{
int x=p[l[i]];
ans[i]+=f[l[i]];
ans[i]-=sum[g[x]-1]*(h[l[i]]);
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>l[i]>>r[i],ans[i]=n-1;
sol();
for(int i=1;i<=n;i++)
{
l[i]=n+n+1-l[i];
r[i]=n+n+1-r[i];
swap(l[i],r[i]);
}
sol();
for(int i=1;i<=n;i++)
cout<<ans[i]<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 15772kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
7 5 4 5 5
result:
ok 5 number(s): "7 5 4 5 5"
Test #2:
score: -100
Runtime Error
input:
200000 342504 342505 248314 248317 259328 259334 234817 234821 225726 225732 371424 371425 260562 260565 34752 34753 132098 132100 262130 262134 7254 7255 228491 228492 43488 43492 188408 188410 11691 11692 350334 350335 327350 327352 360684 360685 182051 182052 72131 72135 194666 194668 61303 61313...