QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#358126#6192. Interval ProblemschrodingerstomWA 30ms29616kbC++142.1kb2024-03-19 17:27:522024-03-19 17:27:52

Judging History

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

  • [2024-03-19 17:27:52]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:29616kb
  • [2024-03-19 17:27:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef unsigned long long ull;
bool memBeg;
template<typename T> void chkmin(T &x,T y) {if(x>y) x=y;}
template<typename T> void chkmax(T &x,T y) {if(x<y) x=y;}
constexpr int mod=1e9+7;
void inc(int &x,int y) {x+=y; x-=(x>=mod)*mod;}
void dec(int &x,int y) {x-=y; x+=(x<0)*mod;}
constexpr int add(int x,int y) {return (x+y>=mod)?x+y-mod:x+y;}
constexpr int sub(int x,int y) {return (x<y)?x-y+mod:x-y;}
constexpr int quick_pow(int x,int times) {
    int ret=1;
    for(;times;times>>=1,x=1ll*x*x%mod) {
        if(times&1) ret=1ll*ret*x%mod;
    }
    return ret;
}
constexpr int maxn=4e5+5;
int n,l[maxn],r[maxn],a[maxn],pmx[maxn],smn[maxn],rpre[maxn],lsuf[maxn];
pli pre[maxn],suf[maxn];
ll ret[maxn];
bool memEn;
void fl() {
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}
int main() {
    fprintf(stderr,"%.24lf\n",fabs(&memEn-&memBeg)/1024.0/1024.0);
    // fl();
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d%d",&l[i],&r[i]);
        a[l[i]]=a[r[i]]=i;
    }
    for(int i=1;i<=2*n;i++) pmx[i]=max(pmx[i-1],r[a[i]]);
    smn[2*n+1]=2*n+1;
    for(int i=2*n;i>=1;i--) smn[i]=min(smn[i+1],l[a[i]]);
    for(int i=1;i<=2*n;i++) rpre[i]=rpre[i-1]+(l[a[i]]==i);
    for(int i=2*n;i>=1;i--) lsuf[i]=lsuf[i+1]+(r[a[i]]==i);
    for(int i=2*n;i>=1;i--) {
        if(pmx[i]<=i);
        else {
            suf[i]=suf[pmx[i]];
            suf[i].second+=rpre[pmx[i]]-rpre[i];
            suf[i].first+=suf[i].second;
        }
        // printf("i = %d, suf = (%lld, %d)\n",i,suf[i].first,suf[i].second);
    }
    for(int i=1;i<=2*n;i++) {
        if(smn[i]>=i);
        else {
            pre[i]=pre[smn[i]];
            pre[i].second+=lsuf[smn[i]]-lsuf[i];
            pre[i].first+=pre[i].second;
        }
        // printf("i = %d, pre = (%lld, %d)\n",i,pre[i].first,pre[i].second);
    }
    for(int i=1;i<=n;i++) ret[i]+=suf[r[i]].first+pre[l[i]].first+n-1;
    for(int i=1;i<=n;i++) printf("%lld\n",ret[i]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Wrong Answer
time: 30ms
memory: 29616kb

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:

200005
200012
200008
200001
200005
200023
199999
199999
199999
200009
200002
199999
200012
200009
200002
200004
199999
200010
200005
200002
199999
200002
199999
199999
199999
199999
200021
200023
200013
200000
199999
199999
200010
200013
200008
200003
200015
200003
200001
200002
199999
200006
200006...

result:

wrong answer 1st numbers differ - expected: '12', found: '200005'