QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202651#6192. Interval Problemucup-team870#RE 0ms15856kbC++143.5kb2023-10-06 12:48:302023-10-06 12:48:30

Judging History

你现在查看的是最新测评结果

  • [2023-10-06 12:48:30]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:15856kb
  • [2023-10-06 12:48:30]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define mm(x) memset(x,0,sizeof x)
#define vl vector<ll>
#define ilr int i,int l,int r
#define ls i<<1,l,mid
#define rs i<<1|1,mid+1,r
#define mi int mid=l+r>>1;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N=2e5+5;
P q[N];
int n,pre[N],r[N],l[N];
ll sum[N]; int num[N];
int v[N<<2],tag[N<<2];
void Max(int &x,int y){x=max(x,y);}
void pd(int i){
    Max(v[i<<1],tag[i]); Max(v[i<<1|1],tag[i]);
    Max(tag[i<<1],tag[i]); Max(tag[i<<1|1],tag[i]);
    tag[i]=0;
}
void ud(int i,int l,int r,int x,int y,int val){
    // cout<<l<<' '<<r<<' '<<x<<' '<<y<<endl;
    if(x>y)return;
    if(l>=x && r<=y){
        // cout<<l<<' '<<r<<'\n';
        Max(v[i],val); Max(tag[i],val); return;
    }
    if(tag[i])pd(i);
    mi
    if(mid>=x)ud(ls,x,y,val);
    if(y>mid)ud(rs,x,y,val);
    v[i]=max(v[i<<1],v[i<<1|1]);
}
int qu(int i,int l,int r,int x,int y){
    // cout<<i<<' '<<l<<' '<<r<<' '<<x<<' '<<y <<'\n';
    if(x>y)return 0;
    if(l>=x && r<=y)return v[i];
    if(tag[i])pd(i);
    mi int res=0;
    if(mid>=x)res=max(res,qu(ls,x,y));
    if(y>mid)res=max(res,qu(rs,x,y));
    return res;
}
int ask(int l,int r){
    return pre[r]-pre[l-1];
}
vector<ll> wk(){
    mm(pre); mm(r); mm(l); mm(sum); mm(num); mm(v); mm(tag);
    int n2=n*2;
    rep(i,1,n){
        auto [u,v]=q[i];
        l[v]=u; r[u]=v; ++pre[u];
    }
    rep(i,1,n2)pre[i]+=pre[i-1];
    per(i,n2,1){
        // cout<<i<<endl;
        if(!r[i])continue;
        int l1=i,r1=r[i];
        ud(1,1,n2,l1,r1,r1);
        int r2=qu(1,1,n2,l1,r1);
        // cout<<l1<<' '<<r1<<' '<<r2<<"hh\n";
        if(r2<=r1){
            sum[i]=num[i]=ask(l1+1,r1-1); continue;
        }
        int l2=l[r2];
        num[i]=num[l2]-ask(l2+1,r1-1)+ask(l1+1,r1-1);
        sum[i]=sum[l2]-ask(l2+1,r1-1)+num[i]; //cout<<l2<<' '<<r1<<' '<<ask(l2+1,r1-1)<<": ";
        // cout<<i<<' '<<r2<<' '<< sum[i]<<' '<<num[i]<<'\n';
    }
    // per(i,n2,1){
    //     if(r[i])cout<<i<<' '<<sum[i]<<' '<<num[i]<<'\n';
    // }
    vector<ll> res(n2+1);
    rep(i,1,n2){
        if(!r[i])continue; int l1=i,r1=r[i];
        int r2=qu(1,1,n2,l1,r1);
        if(r2<=r1)continue;
        int l2=l[r2];
        res[i]=sum[l2]+num[l2]-ask(l2+1,r1-1)*2;
        // cout<<i<<' '<<l2<<' '<<r2<< '\n';  
    }
    // rep(i,1,n2){
    //     if(r[i])cout<<i<<' '<<res[i]<<'\n';
    // }
    return res;
}
ll res[N];
int main() {
    // IOS
    // ud(1,1,10,5,10,10); cout<<qu(1,1,10,2,3); return 0;
    cin>>n; int n2=n*2;
    rep(i,1,n){
        int u,v;cin>>u>>v; q[i]={u,v};
        l[v]=u; r[u]=v; ++pre[u];
    }
    rep(i,1,n2)pre[i]+=pre[i-1];
    int cnt=0;
    rep(i,1,n2){
        if(r[i]){
            res[i]=cnt+ask(i+1,r[i]-1); ++cnt;
            // cout<<i<<' '<<res[i]<<endl;
        }
        else --cnt;
    }
    auto res1=wk();
    // cout<<"wk1#########\n";
    rep(i,1,n2)res[i]+=res1[i];
    rep(i,1,n){
        auto [u,v]=q[i];  u=n2+1-u; v=n2+1-v; swap(u,v); q[i]={u,v};
    }
    auto res2=wk();
    rep(i,1,n){
        res[n2+1-q[i].second]+=res2[q[i].first];
    }
    rep(i,1,n){
        auto [u,v]=q[i]; u=n2+1-u; v=n2+1-v; swap(u,v); q[i]={u,v};
    }
    rep(i,1,n){
        cout<<res[q[i].first]<<'\n';
    }
}
/*
5
2 3
6 7
1 9
5 10
4 8
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 15856kb

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...

output:


result: