QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#272314#6420. Certain Scientific Railgungao_ycWA 43ms18184kbC++144.9kb2023-12-02 16:52:352023-12-02 16:52:37

Judging History

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

  • [2023-12-02 16:52:37]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:18184kb
  • [2023-12-02 16:52:35]
  • 提交

answer

#include<bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define ll long long
using namespace std;
const int N=1e5+10;
int n,bl[N],br[N];
struct node{
    int x,y;
}a[N];
pair<int,int> yl[N],yr[N],yy[N];
ll ans;
int op,val[N];
ll t1[N<<2],t2[N<<2],tag[N<<2];
void upd(int x,int k){t1[x]+=k;t2[x]+=k;tag[x]+=k;}
void pushdown(int x){if(tag[x]){upd(ls,tag[x]);upd(rs,tag[x]);tag[x]=0;}}
void pushup(int x){t1[x]=min(t1[ls],t1[rs]);t2[x]=min(t2[ls],t2[rs]);}
void build(int x,int l,int r){
    tag[x]=0;
    if(l==r){t1[x]=val[l]+br[l-1];t2[x]=val[l]+br[l-1]*2;return;}
    int mid=(l+r)>>1;
    build(ls,l,mid);build(rs,mid+1,r);
    pushup(x);
}
void modify(int x,int l,int r,int L,int R,int k){
    if(L>R) return;
    if(L<=l&&r<=R) return upd(x,k);
    int mid=(l+r)>>1;pushdown(x);
    if(L<=mid) modify(ls,l,mid,L,R,k);
    if(mid<R) modify(rs,mid+1,r,L,R,k);
    pushup(x);
}
int st1[N],tp1,st2[N],tp2;
void print(int x,int l,int r){
    if(l==r) {printf("%d ",t1[x]);return;}
    int mid=(l+r)>>1;
    print(ls,l,mid);print(rs,mid+1,r);
}
int main(){
    int T;scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        int nl=0,nr=0;ans=1e16;
        for(int i=1;i<=n;++i){
            scanf("%d%d",&a[i].x,&a[i].y);
            if(a[i].x<0) bl[++nl]=-a[i].x;
            if(a[i].x>0) br[++nr]=a[i].x;
        }
        sort(bl+1,bl+nl+1);sort(br+1,br+nr+1);
        nl=unique(bl+1,bl+nl+1)-bl-1;nr=unique(br+1,br+nr+1)-br-1;
        // printf("nl=%d nr=%d\n",nl,nr);
        for(int i=1;i<=n;++i){
            if(a[i].x<0)
                a[i].x=lower_bound(bl+1,bl+nl+1,-a[i].x)-bl,yl[a[i].x].first=max(yl[a[i].x].first,a[i].y),yl[a[i].x].second=min(yl[a[i].x].second,a[i].y);
            else if(a[i].x>0)
                a[i].x=lower_bound(br+1,br+nr+1,a[i].x)-br,yr[a[i].x].first=max(yr[a[i].x].first,a[i].y),yr[a[i].x].second=min(yr[a[i].x].second,a[i].y);
        }
        for(int i=nr;i;--i) yr[i].first=max(yr[i].first,yr[i+1].first),yr[i].second=min(yr[i].second,yr[i+1].second);
        val[nr+1]=0;
        // puts("yl:");
        // for(int i=1;i<=nl;++i) printf("%d %d\n",yl[i].first,yl[i].second);
        // puts("yr:");
        // for(int i=1;i<=nr;++i) printf("%d %d\n",yr[i].first,yr[i].second);
        tp1=tp2=0;
        for(int i=1;i<=nr;++i){
            val[i]=1ll*2*yr[i].first-yr[i].second;
            if(yr[i].first>yr[i+1].first) st1[++tp1]=i;
            if(yr[i].second<yr[i+1].second) st2[++tp2]=i;
        }
        build(1,1,nr+1);
            // print(1,1,nr+1);puts("");
        ans=min(ans,min(t1[1]+2*bl[nl],t2[1]+bl[nl]));
        for(int i=nl,ny1=0,ny2=0;i;--i){
            if(ny1<yl[i].first){
                for(;tp1&&yr[st1[tp1]].first<=yl[i].first;--tp1) modify(1,1,nr+1,st1[tp1]+1,nr+1,2*(yr[st1[tp1]].first-ny1)),ny1=yr[st1[tp1]].first;
                modify(1,1,nr+1,st1[tp1]+1,nr+1,2*(yl[i].first-ny1));
                ny1=yl[i].first;
            }
            // print(1,1,nr+1);puts("");
            if(ny2>yl[i].second){
                for(;tp2&&yr[st2[tp2]].second>=yl[i].second;--tp2) modify(1,1,nr+1,st2[tp2]+1,nr+1,ny2-yr[st2[tp2]].second),ny2=yr[st2[tp2]].second;
                modify(1,1,nr+1,st2[tp2]+1,nr+1,ny2-yl[i].second);
                ny2=yl[i].second;
            }
            // printf("%d %d\n",ny1,ny2);
            // printf("t: %d %d\n",t1[1],t2[1]);
            ans=min(ans,min(t1[1]+2*bl[i-1],t2[1]+bl[i-1]));
            // printf("%d %d\n",t1[1]+2*bl[i-1],t2[1]+bl[i-1]);
        }
        tp1=tp2=0;
        for(int i=1;i<=nr;++i){
            val[i]=1ll*yr[i].first-2*yr[i].second;
            if(yr[i].first>yr[i+1].first) st1[++tp1]=i;
            if(yr[i].second<yr[i+1].second) st2[++tp2]=i;
        }
        // puts("end 1");
        build(1,1,nr+1);
        // print(1,1,nr+1);puts("");
        ans=min(ans,min(t1[1]+2*bl[nl],t2[1]+bl[nl]));
        for(int i=nl,ny1=0,ny2=0;i;--i){
            if(ny1<yl[i].first){
                for(;tp1&&yr[st1[tp1]].first<=yl[i].first;--tp1) 
                    modify(1,1,nr+1,st1[tp1]+1,nr+1,yr[st1[tp1]].first-ny1),ny1=yr[st1[tp1]].first;
                modify(1,1,nr+1,st1[tp1]+1,nr+1,yl[i].first-ny1);
                ny1=yl[i].first;
            }
            // print(1,1,nr+1);puts("");
            if(ny2>yl[i].second){
                for(;tp2&&yr[st2[tp2]].second>=yl[i].second;--tp2) modify(1,1+1,nr+1,st2[tp2]+1,nr+1,2*(ny2-yr[st2[tp2]].second)),ny2=yr[st2[tp2]].second;
                modify(1,1,nr+1,st2[tp2]+1,nr+1,2*(ny2-yl[i].second));
                ny2=yl[i].second;
            }
            // printf("%d %d\n",ny1,ny2);
            // printf("t: %d %d\n",t1[1],t2[1]);
            ans=min(ans,min(t1[1]+2*bl[i-1],t2[1]+bl[i-1]));
        }
        for(int i=1;i<=nl;++i) yl[i]={0,0};
        for(int i=1;i<=nr;++i) yr[i]={0,0};
        printf("%lld\n",ans);
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 11784kb

input:

3
2
0 1
1 0
4
1 1
-3 -3
4 -4
-2 2
4
1 100
3 100
-100 1
3 -100

output:

0
8
4

result:

ok 3 number(s): "0 8 4"

Test #2:

score: 0
Accepted
time: 2ms
memory: 11868kb

input:

120
4
11 11
-22 -22
33 -33
-44 44
4
-11 11
22 -22
-33 -33
44 44
4
-11 -11
22 22
-33 33
44 -44
4
11 -11
-22 22
33 33
-44 -44
4
-11 11
22 -22
33 33
-44 -44
4
11 11
-22 -22
-33 33
44 -44
4
11 -11
-22 22
-33 -33
44 44
4
-11 -11
22 22
33 -33
-44 44
4
1 1
-2 -2
3 -3
-4 4
4
-1 1
2 -2
-3 -3
4 4
4
-1 -1
2 2
...

output:

99
99
99
99
99
99
99
99
9
9
9
9
9
9
9
9
5
5
5
5
5
5
5
5
4
4
4
4
4
4
4
4
0
0
0
0
0
0
0
0
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
12
12
12
12
12
12
12
12
0
0
0
0
0
0
0
0
11
11
11
11
11
11
11
11
111
111
111
111
111
111
111
111
300
300
300
300
300
300
300
300
5
5
5
5
5
5
5
5
2
2
2
2
2
2
2
2
48
48
48
48
48
48
48...

result:

ok 120 numbers

Test #3:

score: 0
Accepted
time: 24ms
memory: 16964kb

input:

1
100000
259716243 240441467
199457754 301066970
412772262 87809313
139833960 359731944
453667163 46926477
204936243 294432582
361538994 138967777
315714786 184515556
274799986 224851893
315004381 184713646
104778725 394583171
100521423 399036944
392072619 107037839
19992953 480118328
166443446 3325...

output:

500573654

result:

ok 1 number(s): "500573654"

Test #4:

score: 0
Accepted
time: 33ms
memory: 17144kb

input:

1
100000
231900334 268958119
8094073 491651466
181235767 318579810
152422229 348402615
453103138 47722205
169802544 329762126
66615606 433110853
63974760 435613334
412296501 86899836
380626267 120285438
234254409 265425647
343489254 155604658
456112096 43577922
389402607 110812358
361862073 13733807...

output:

500924008

result:

ok 1 number(s): "500924008"

Test #5:

score: 0
Accepted
time: 29ms
memory: 16912kb

input:

1
100000
243687982 257271514
406262214 92746823
115474686 384860427
179141355 321775276
111057575 388052482
85754748 413966937
89015940 411624061
97395736 402451385
394966118 105231558
118633450 381544518
121485690 377952946
93095255 406155875
285623743 214726445
230422095 268632132
137612706 361757...

output:

1001565829

result:

ok 1 number(s): "1001565829"

Test #6:

score: 0
Accepted
time: 29ms
memory: 18184kb

input:

1
100000
450661745 49199859
46152367 453651505
490854754 8343231
273253564 227017249
177014519 322480838
295759745 203932936
261849726 238301630
64867210 434153377
105275689 393750931
321581727 178232552
494756932 6104054
31280896 468013695
46903507 453060294
162085346 337538866
239622896 259681652
...

output:

1001452257

result:

ok 1 number(s): "1001452257"

Test #7:

score: 0
Accepted
time: 43ms
memory: 15796kb

input:

1
100000
150929109 349489222
6420724 493823770
464662613 35982721
402411960 97813587
40230561 460488339
470554995 30114056
344276320 154962447
219702967 280132033
104632512 395604723
479497355 19601658
117766907 383020273
36133778 463836986
175546685 324588426
43749701 456053065
130176612 369176811
...

output:

1501257683

result:

ok 1 number(s): "1501257683"

Test #8:

score: 0
Accepted
time: 18ms
memory: 15948kb

input:

8
10000
108715119 390304225
45853335 454319274
399590321 101245208
273660814 225432152
97670975 403201669
476219330 23861282
58911490 440808774
128367407 370649954
306462809 192987122
396996806 103458329
129292472 370369176
135445802 364903545
9556524 491441067
272140862 228185209
394219336 10628059...

output:

499504970
499504970
499504970
499504970
499504970
499504970
499504970
499504970

result:

ok 8 numbers

Test #9:

score: 0
Accepted
time: 21ms
memory: 11988kb

input:

8
10000
88475214 411685526
295971508 203464188
475025201 25141393
312127126 188194692
19542945 480366130
488061278 12628967
186934840 313365863
481957571 18601403
358812248 140919718
22594424 477659644
217700756 281415099
165264320 334364787
117366326 382623925
104117966 396054687
249226386 25018520...

output:

1000322231
1000322231
1000322231
1000322231
1000322231
1000322231
1000322231
1000322231

result:

ok 8 numbers

Test #10:

score: 0
Accepted
time: 24ms
memory: 14280kb

input:

8
10000
269878538 230854020
456626682 43333438
434144544 66494813
232368812 267733469
68096662 431017351
17852539 482545915
87803855 412171111
265856716 234461260
115315829 384621424
31746172 467793722
373607866 126486181
23907446 476867982
333063328 166736814
343578833 156172707
244551435 255629961...

output:

1000479661
1000479661
1000479661
1000479661
1000479661
1000479661
1000479661
1000479661

result:

ok 8 numbers

Test #11:

score: 0
Accepted
time: 24ms
memory: 12276kb

input:

8
10000
159480657 340897530
349562243 150040650
173755554 326392525
282856769 217394893
392793822 107352227
491621792 7387423
440310768 58951882
187152471 313516759
227502759 272030922
48462295 450696921
183559088 317228169
365794915 133411085
345365867 154485210
493284111 6477090
397676402 10174717...

output:

1000582139
1000582139
1000582139
1000582139
1000582139
1000582139
1000582139
1000582139

result:

ok 8 numbers

Test #12:

score: 0
Accepted
time: 30ms
memory: 11956kb

input:

8
10000
445062805 54324634
73636583 427209121
94242291 406610072
426842404 73694287
124540787 376414432
56028719 443696776
390646024 108939638
322649687 177349434
398037737 102667192
130048845 369861315
51589239 448100026
11585337 488662930
291289277 208605416
314642705 186222797
405227467 95703222
...

output:

1497536843
1497536843
1497536843
1497536843
1497536843
1497536843
1497536843
1497536843

result:

ok 8 numbers

Test #13:

score: -100
Wrong Answer
time: 9ms
memory: 12044kb

input:

5000
16
29 -33
-5 -42
3 -2
-21 -32
11 43
-12 28
50 10
-31 47
49 -11
43 -45
-30 33
-34 -40
18 49
-50 8
31 8
-6 -31
14
34 6
31 -7
48 16
-18 23
44 -35
7 -49
-12 -48
15 3
7 -15
9 18
-21 -8
24 32
-3 44
5 -12
17
16 20
4 46
18 -38
-19 -43
-36 9
-28 -38
38 9
35 40
27 -31
37 -24
-28 -3
3 -11
16 41
4 -43
-48 ...

output:

126
90
126
54
86
118
125
8
116
123
94
63
94
46
100
103
82
88
91
108
116
111
38
88
109
121
11
16
133
40
52
139
126
44
133
24
70
101
122
105
86
52
32
122
44
30
87
35
95
99
78
109
133
64
82
80
111
22
123
108
92
144
104
62
60
102
67
49
22
98
58
119
109
138
75
71
133
90
88
91
59
110
119
136
9
94
85
105
6...

result:

wrong answer 109th numbers differ - expected: '68', found: '69'