QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#177298 | #6192. Interval Problem | PhantomThreshold# | RE | 0ms | 22052kb | C++20 | 3.6kb | 2023-09-12 20:00:55 | 2023-09-12 20:00:55 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const int maxn = 210000;
int n,N;
struct node
{
int l,r,i;
}a[maxn];
inline bool cmp(const node &k1,const node &k2)
{
return k1.r<k2.r;
}
int adl[maxn],sbl[maxn],covl[maxn];
set<int>S;
int nowl[maxn],nowr[maxn];
int li[maxn];
int sum[maxn],pl[maxn];
int f[maxn],g[maxn];
void init()
{
for(int i=1;i<=n;i++)
{
nowl[a[i].i]=a[i].l;
nowr[a[i].i]=a[i].r;
}
for(int i=1;i<=n;i++) covl[i]=N+1;
for(int i=1;i<=N;i++) adl[i]=sbl[i]=0;
for(int i=1;i<=n;i++) adl[a[i].l]=a[i].i, sbl[a[i].r]=a[i].i;
for(int i=1;i<=N;i++)
{
if(adl[i])
{
int j=adl[i];
if(!S.empty())
{
auto it=S.begin();
covl[j]= *it;
}
S.insert( nowl[j] );
}
if(sbl[i]) S.erase( nowl[sbl[i]] );
}
for(int i=1;i<=n;i++) f[i]=g[i]=0;
for(int i=1;i<=n;i++) li[a[i].l]=a[i].i;
for(int i=1;i<=N;i++) sum[i]=0,pl[i]=N+1;
}
void add(int x)
{
for(;x<=N;x+=lowbit(x)) sum[x]++;
}
void upd(int x,int c)
{
for(;x<=N;x+=lowbit(x)) pl[x]=min(pl[x],c);
}
int querysum(int x)
{
int re=0;
for(;x;x-=lowbit(x)) re+=sum[x];
return re;
}
int querymn(int x)
{
int re=N+1;
for(;x;x-=lowbit(x)) re=min(re,pl[x]);
return re;
}
int ans[maxn];
int num[maxn];
signed main()
{
ios_base::sync_with_stdio(false); ////////////////////////////////////////
cin.tie(0);
cin>>n; N=n<<1;
for(int i=1;i<=n;i++)
{
cin>>a[i].l>>a[i].r;
a[i].i=i;
}
sort(a+1,a+n+1,cmp);
init();
for(int i=1;i<=n;i++)
{
int id=a[i].i;
int cvl= covl[id];
int pi= querymn(N-a[i].l+1);
if( min(pi,cvl) >= a[i].l )
{
g[id]= querysum(a[i].r)-querysum(a[i].l-1)+1;
f[id]= g[id]-1;
}
else
{
if(pi<=cvl)
{
pi=li[pi];
int gap= querysum(a[i].r)-querysum(nowr[pi]);
g[id]= g[pi] + gap +1;
f[id]= gap+ f[pi] + g[pi] - ( querysum(nowr[pi]-1)-querysum(a[i].l) );
}
else //cvl < pi
{
g[id]= querysum(a[i].r)-querysum(cvl-1)+1;
f[id]= g[id]-1+ querysum(a[i].l-1)-querysum(cvl-1);
pi= querymn(N-cvl+1);
if(pi<cvl)
{
pi=li[pi];
int adg= g[pi]- ( querysum(nowr[pi])-querysum(cvl-1) );
g[id] += adg;
f[id] += f[pi] + g[pi]*2 - (g[pi]-adg)*3 +1;
}
}
}
num[id]+= querysum(a[i].r);
add(a[i].r);
upd(N-a[i].r+1,a[i].l);
}
for(int i=1;i<=n;i++) ans[i]+=f[i];
for(int i=1;i<=n;i++)
{
a[i].l= N-a[i].l+1;
a[i].r= N-a[i].r+1;
swap(a[i].l,a[i].r);
}
sort(a+1,a+n+1,cmp);
init();
for(int i=1;i<=n;i++)
{
int id=a[i].i;
int cvl= covl[id];
int pi= querymn(N-a[i].l+1);
if( min(pi,cvl) >= a[i].l )
{
g[id]= querysum(a[i].r)-querysum(a[i].l-1)+1;
f[id]= g[id]-1;
}
else
{
if(pi<=cvl)
{
pi=li[pi];
int gap= querysum(a[i].r)-querysum(nowr[pi]);
g[id]= g[pi] + gap +1;
f[id]= gap+ f[pi] + g[pi] - ( querysum(nowr[pi]-1)-querysum(a[i].l) );
}
else //cvl < pi
{
g[id]= querysum(a[i].r)-querysum(cvl-1)+1;
f[id]= g[id]-1+ querysum(a[i].l-1)-querysum(cvl-1);
pi= querymn(N-cvl+1);
if(pi<cvl)
{
pi=li[pi];
int adg= g[pi]- ( querysum(nowr[pi])-querysum(cvl-1) );
g[id] += adg;
f[id] += f[pi] + g[pi]*2 - (g[pi]-adg)*3 +1;
}
}
}
num[id]+= querysum(a[i].r);
add(a[i].r);
upd(N-a[i].r+1,a[i].l);
}
for(int i=1;i<=n;i++) ans[i]+=f[i];
for(int i=1;i<=n;i++) ans[i]+= n-num[i]-1;
for(int i=1;i<=n;i++) cout<<ans[i]<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 22052kb
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...