QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#383590#7436. Optimal Ordered Problem Solvermarher20 3986ms279604kbC++175.6kb2024-04-09 15:41:582024-04-09 15:41:59

Judging History

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

  • [2024-04-09 15:41:59]
  • 评测
  • 测评结果:20
  • 用时:3986ms
  • 内存:279604kb
  • [2024-04-09 15:41:58]
  • 提交

answer

#pragma GCC optimize("Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+200;

namespace IO {
#define iL (1 << 20)
char ibuf[iL], *iS = ibuf + iL, *iT = ibuf + iL;
#define gc() ((iS == iT) ? (iT = (iS = ibuf) + fread(ibuf, 1, iL, stdin), iS == iT ? EOF : *iS ++) : *iS ++)
template<class T> inline void read(T &x) {
  x = 0;int f = 0;char ch = gc();
  for (; !isdigit(ch); f |= ch == '-', ch = gc());
  for (; isdigit(ch); x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc());
  x = (f == 1 ? ~ x + 1 : x);
}
template<class T, class... Args> inline void read(T &x, Args&... args) { read(x), read(args...); }
template<class T> inline void readch(T &x) { char ch = gc(); for (; !isalpha(ch); ch = gc()); x = ch; }
char Out[iL], *iter = Out;
#define flush() fwrite(Out, 1, iter - Out, stdout), iter = Out
template<class T> inline void write(T x, char ch = '\n') {
  T l, c[35];
  if (x < 0) *iter ++ = '-', x = ~ x + 1;
  for (l = 0; !l || x; c[l] = x % 10, l++, x /= 10);
  for (; l; -- l, *iter ++ = c[l] + '0');*iter ++ = ch;
  flush();
}
template<class T, class... Args> inline void write(T x, Args... args) { write(x, ' '), write(args...); }
} // IO
using namespace IO;

struct poi
{
    int x,y;

    friend bool operator<(poi a,poi b)
    {
        return a.y==b.y?a.x>b.x:a.y<b.y;
    }

    int in(poi t)
    {
        return (t.x>=x)&(t.y>=y);
    }
}a[N];

bool cmp(poi a,poi b)
{
    return a.y==b.y?a.x>=b.x:a.y<b.y;
}

struct node
{
    poi l,r,w,la;int opt,siz,rd;

    void mk(poi d,int o)
    {
        if(o&1)opt|=1,l.y=r.y=w.y=la.y=d.y;
        if(o&2)opt|=2,l.x=r.x=w.x=la.x=d.x;
    }
}t[N];

int n,m,ans[N],mx[N],ch[N][2],tot,ro,now,mi[N];

#define ls ch[x][0]
#define rs ch[x][1]

void up(int x)
{
    t[x].l=ls?t[ls].l:t[x].w;
    t[x].r=rs?t[rs].r:t[x].w;
    t[x].siz=t[ls].siz+t[rs].siz+1;
}

int make_new(poi w)
{
    int x=++tot;
    t[x]=(node){w,w,w,(poi){},0,1,rand()%10000000};
    return x;
}

void down(int x)
{
    if(!t[x].opt)return;
    if(ls)t[ls].mk(t[x].la,t[x].opt);
    if(rs)t[rs].mk(t[x].la,t[x].opt);
    t[x].opt=0;
}

void split(int x,poi k,int&a,int&b)
{
    if(!x)a=b=0;
    else
    {
        down(x);
        if(cmp(k,t[x].w))a=x,split(rs,k,rs,b);
        else b=x,split(ls,k,a,ls);
        up(x);
    }
}

int merge(int a,int b)
{
    if(!a||!b)return a+b;
    int w;
    if(t[a].rd<t[b].rd)ch[a][1]=merge(ch[a][1],b),up(a),w=a;
    else ch[b][0]=merge(a,ch[b][0]),up(b),w=b;
    return w;
}

void dfs(int x,poi d,int opt)
{
    if(!x)return;
    if(t[x].l.in(d)&&t[x].r.in(d))return t[x].mk(d,opt);
    if(t[x].r.y>d.y||t[x].l.x>d.x)return;
    down(x);dfs(ls,d,opt);dfs(rs,d,opt);
    if(t[x].w.in(d))
    {
        if(opt==1)t[x].w.y=d.y;
        else t[x].w.x=d.x;
    }
    up(x);
}

int find(int x,poi d)
{
    if(!x||t[x].r.y>d.y||t[x].l.x>d.x)return 0;
    if(t[x].l.in(d)&&t[x].r.in(d))return t[x].siz;
    down(x);return find(ls,d)+find(rs,d)+t[x].w.in(d);
}

void insert(int d,int x)
{
    for(int i=d;i<=n;i+=(i&(-i)))mi[i]=min(mi[i],x);
}

int Find(int d)
{
    int ans=1e9;
    for(int i=d;i;i-=(i&(-i)))ans=min(ans,mi[i]);
    return ans;
}

void rinsert(int x,int y)
{
    x=n-x+1;
    for(int i=x;i<=n;i+=(i&(-i)))mx[i]=max(mx[i],y);
}

int rfind(int x)
{
    x=n-x+1;int ans=0;if(x<0)return 0;
    for(int i=x;i;i-=(i&(-i)))ans=max(ans,mx[i]);
    return ans;
}

struct tree
{
    int p[N];

    void insert(int x,int d)
    {
        for(int i=x;i<=n;i+=(i&(-i)))p[i]+=d;
    }

    int find(int x)
    {
        int ans=0;
        for(int i=x;i;i-=(i&(-i)))ans+=p[i];
        return ans;
    }
}xx,yy,pp;

vector<int>ad[N];

struct pask
{
    int opt,x,y,id;

    friend bool operator<(pask a,pask b)
    {
        return a.x==b.x?(a.opt==b.opt?a.y<b.y:a.opt<b.opt):a.x>b.x;
    }
}rq[N];

vector<pair<int,int>>ask[N];

struct que
{
    int opt,x,y,X,Y;

    void in()
    {
        read(opt,x,y,X,Y);
    }
}ak[N];

poi st[N];int rr[N];

int main()
{
    srand(19260817);
    // freopen("in","r",stdin);
    // freopen("out","w",stdout);
    read(n,m);now=n;
    for(int i=1;i<=n;i++)read(a[i].x,a[i].y),xx.insert(a[i].x,1),yy.insert(a[i].y,1);
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)rq[i]=(pask){1,a[i].x,a[i].y,i};
    for(int i=1;i<=m;i++)ak[i].in(),rq[i+n]=(pask){0,ak[i].x,ak[i].y,i};
    for(int i=1;i<=n;i++)mi[i]=1e9+7;sort(rq+1,rq+1+n+m);
    for(int i=1;i<=n+m;i++)
    {
        if(rq[i].opt==0)insert(n-rq[i].y+1,rq[i].id);
        else
        {
            int w=Find(n-rq[i].y+1);
            if(w<=m)ad[w].push_back(rq[i].id);
        }
    }
    for(int i=1;i<=m;i++)
    {
        auto [opt,x,y,X,Y] = ak[i];
        rinsert(x,y);dfs(ro,(poi){x,y},opt);
        int top=0;
        for(auto d:ad[i])
        {
            auto o=a[d];
            xx.insert(o.x,-1),yy.insert(o.y,-1);
            if(opt==1)o.y=y;else o.x=x;
            st[++top]=o;
        }
        now-=ad[i].size();
        rr[top]=ro;
        for(int i=top;i>=1;i--)split(rr[i],st[i],rr[i],rr[i-1]);
        for(int i=top;i>=1;i--)rr[i-1]=merge(merge(rr[i],make_new(st[i])),rr[i-1]);
        ro=rr[0];
        if(rfind(X+1)>Y)continue;
        ans[i]=find(ro,(poi){X,Y})+xx.find(X)+yy.find(Y)-now;
        ask[Y].push_back(make_pair(X,i));
    }
    for(int i=n,pos=n;i>=1;i--)
    {
        for(auto x:ask[i])ans[x.second]+=pp.find(n-x.first);
        while(pos&&a[pos].y==i)pp.insert(n-a[pos].x+1,1),pos--;
    }
    for(int i=1;i<=m;i++)write(ans[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 122552kb

input:

995 996
950 481
376 18
141 776
711 966
130 727
468 529
47 39
857 563
832 821
776 472
154 914
825 279
332 415
470 361
968 440
45 560
299 755
703 785
744 387
547 382
3 549
344 573
778 424
784 765
280 115
251 434
695 98
463 506
379 38
610 486
305 623
703 244
856 365
117 360
772 847
331 723
663 991
900 ...

output:

423
473
758
313
694
232
333
784
821
154
247
244
504
54
200
370
872
782
734
174
660
467
76
754
77
3
144
974
526
415
439
694
507
577
258
120
243
3
2
319
313
498
218
828
433
623
981
700
120
55
70
499
375
283
387
128
317
139
220
410
22
547
3
385
430
168
32
0
178
625
677
561
488
672
577
64
144
537
235
54...

result:

wrong answer 210th numbers differ - expected: '9', found: '7'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 733ms
memory: 251240kb

input:

999996 999996
921339 140126
955508 363759
958698 342406
280137 955674
907511 75721
189876 946586
152058 168837
541857 557702
84498 865987
185574 809224
704828 701026
815379 548000
989515 518951
335439 336866
745570 790616
766723 212893
926629 859003
51261 40866
592510 556235
324926 700261
320946 798...

output:

0
0
953730
0
0
561967
0
0
0
0
459917
0
0
0
0
420
0
0
0
0
0
0
562549
0
0
0
0
0
0
0
0
0
0
0
11756
0
0
7822
0
0
0
0
22726
0
0
0
8233
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
13818
414667
0
0
0
0
0
0
6803
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
10965
0
0
0
0
0
0
0
15675
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 6th numbers differ - expected: '512663', found: '561967'

Subtask #3:

score: 20
Accepted

Test #17:

score: 20
Accepted
time: 3172ms
memory: 272496kb

input:

999995 999997
261379 334440
985281 986034
549380 718157
670003 253925
533027 437989
326806 983213
965935 756259
229069 686789
331338 684961
957559 390618
937820 959719
338153 779814
582581 965418
634156 421264
308778 938878
913059 390904
481477 431492
739774 793015
901442 934600
256704 991485
366691...

output:

160635
633543
123519
313576
450015
383636
574186
2373
203701
326075
117994
567275
652824
199778
380317
380374
105875
373857
788346
703176
609801
648161
367059
497975
57979
478851
745054
75935
543062
251837
769828
436489
480966
235835
509625
757188
763486
396842
262680
2240
267171
165787
558963
16523...

result:

ok 999997 numbers

Test #18:

score: 0
Accepted
time: 1695ms
memory: 278812kb

input:

999995 1000000
503105 994319
301845 645636
538613 176453
944222 13642
220616 61270
445661 771824
758217 940994
11782 103262
159910 298805
317312 333018
741333 381578
579921 219986
605953 400913
625208 245340
729891 669648
186684 920562
118589 936228
281749 70955
103542 8281
854584 972667
663720 1425...

output:

8906
95485
8020
794529
288722
194571
738405
141163
47184
574675
21317
361918
336935
752285
747548
767325
485498
549919
836009
224230
243311
43089
166877
861403
1740
800031
757202
757248
571568
258896
110506
308599
111448
82706
495681
126271
557664
498332
507141
161535
251016
116433
490396
350530
854...

result:

ok 1000000 numbers

Test #19:

score: 0
Accepted
time: 3920ms
memory: 279604kb

input:

999997 1000000
44415 540937
815519 772048
580901 820033
176932 136598
26200 658165
495640 298186
350660 672003
66843 751311
886121 454924
75107 454946
855867 668594
952401 723257
914495 648341
931555 500560
451289 811080
275183 969584
28984 255298
971792 603789
290513 485349
63131 4066
4993 123137
6...

output:

629719
695599
351561
83909
248197
337451
198910
119007
163901
59655
227999
446205
417989
21251
943060
809056
530827
874242
191820
190031
801897
103766
56477
114351
865146
677995
221128
278416
622213
580214
223576
311442
602474
22418
10224
852728
546723
793775
936547
18769
695901
400642
163668
131209...

result:

ok 1000000 numbers

Test #20:

score: 0
Accepted
time: 3790ms
memory: 278056kb

input:

999995 999995
583944 643022
937405 396314
664613 53634
851937 959727
682251 262542
332058 495766
657697 254050
368945 648181
175500 409923
987447 663924
254362 212955
27186 48916
280933 263728
376404 531873
991175 304206
637107 818051
718055 603621
219979 376988
818262 602594
182634 716446
199549 42...

output:

632589
674038
421313
484901
850231
228438
726812
388070
754679
535180
282906
25258
23979
984419
946557
113528
158768
603008
400873
344667
550891
469199
301296
257606
310724
113289
667078
869781
273972
414507
36966
141760
266471
765423
406244
590218
968606
19385
46201
1519
39710
219752
427711
92415
6...

result:

ok 999995 numbers

Test #21:

score: 0
Accepted
time: 3239ms
memory: 270284kb

input:

1000000 1000000
447619 721571
584229 399494
614240 965088
204795 826646
448424 16919
866545 997174
657300 767860
490299 320401
773237 573187
494243 285955
630714 533001
811444 822428
571608 72868
490258 309897
415722 410945
967983 117451
928078 616204
939548 894410
622192 510197
568931 946541
594774...

output:

126935
145263
465828
476012
65533
42535
698958
492977
890460
175334
194482
579490
712753
695360
739259
853109
150308
228326
104307
750668
105724
512722
81223
925835
382011
92740
184439
918760
104781
443444
190528
204480
31387
835933
934756
66557
530040
18748
381135
735303
30969
306423
125340
33784
7...

result:

ok 1000000 numbers

Test #22:

score: 0
Accepted
time: 3929ms
memory: 275104kb

input:

1000000 1000000
563011 69168
799795 322619
625047 265910
302908 329651
912744 87238
944646 651913
883129 540212
154443 308737
809426 72823
394629 784304
722788 621382
600870 838097
351383 148859
863544 219752
279356 573627
168233 338737
748815 773018
779663 11919
819024 722313
784467 172146
429478 8...

output:

931763
507651
2891
279771
232600
358080
668537
179794
209284
323888
8579
28498
724380
790693
913562
742416
237268
811986
666427
110749
337341
45733
893515
541297
415398
387692
840824
806569
300977
7251
210484
844863
141462
768680
694505
368468
120097
826126
58764
335812
638189
244154
574681
705704
4...

result:

ok 1000000 numbers

Test #23:

score: 0
Accepted
time: 3986ms
memory: 278372kb

input:

999999 999998
549904 780695
952102 832337
321082 698470
315767 459429
88631 296205
224845 246509
898700 395777
277973 403130
437048 186188
393884 45421
993904 511710
94564 534733
606016 40744
294330 813572
957779 147335
315712 805921
835751 978801
764915 214826
33564 855982
174621 309776
202372 4386...

output:

174929
683585
23870
145186
591016
146066
527528
825193
571238
633087
677612
57791
250466
20273
94886
182538
544573
426519
148353
8778
283430
226442
23493
85639
27407
955906
174708
192446
139541
672132
487223
351873
370386
161299
345077
163475
831109
778917
16063
732
359442
2254
570035
292433
527730
...

result:

ok 999998 numbers

Test #24:

score: 0
Accepted
time: 3882ms
memory: 274768kb

input:

1000000 1000000
875926 620802
927410 582189
453297 27134
625927 194770
285863 198107
758448 934846
628394 508725
472741 244210
63544 906210
694594 426018
95086 100899
791006 237438
459186 660344
422538 932319
786905 189449
38062 851236
615341 58794
935296 669950
41835 430485
638425 532888
887360 956...

output:

314353
240231
222662
88736
363994
50619
459541
704120
315257
144316
755815
369269
315280
552329
382758
939953
104281
715086
891561
724596
298843
885639
44610
110591
551022
693346
436359
15173
17290
155448
18605
889862
815068
470390
238390
874503
68546
21916
704446
344934
357808
355718
103549
888118
...

result:

ok 1000000 numbers

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%