QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#527895#7436. Optimal Ordered Problem SolverCrying0 3903ms168264kbC++146.3kb2024-08-22 22:05:352024-08-22 22:05:36

Judging History

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

  • [2024-08-22 22:05:36]
  • 评测
  • 测评结果:0
  • 用时:3903ms
  • 内存:168264kb
  • [2024-08-22 22:05:35]
  • 提交

answer

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#include<bits/stdc++.h>
#define lc(x) (t[x].lc)
#define rc(x) (t[x].rc)
#define lowbit(x) (x&(-x))
using namespace std;
namespace io {
    const int __SIZE = (1 << 21) + 1;
    char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
    #define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
    inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
    inline void gc (char &x) { x = Gc(); }
    inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
    inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
    inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
        for(; __c > 31 && __c < 127 && __c != ' ' && __c != '\n' && __c != '\r'; ++s, __c = Gc()) *s = __c; *s = 0; }
    template <class I> inline bool gi (I &x) { _eof = 0;
        for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
        for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
    template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
        while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
    struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

typedef long long ll;
typedef vector<int> vec; 
typedef array<int,2> pr;
const int MAXN = 1e6+10,INF = 1e9;
template<typename T>void tomin(T& x,T y){x = min(x,y);}
template<typename T>void tomax(T& x,T y){x = max(x,y);}
//
int n,m,x[MAXN],y[MAXN];
int o[MAXN],mx[MAXN],my[MAXN],qx[MAXN],qy[MAXN],ans[MAXN];

vec ap[MAXN]; int mt[MAXN],qt[MAXN];

struct BIT{
    int t[MAXN];
    void mdf(int x,int v){x=n-x+1;for(;x<=n;x+=lowbit(x))t[x] += v;}
    int qry(int x,int S=0){x=n-x+1;for(;x;x-=lowbit(x))S+=t[x]; return S;}
}tx,ty,tz;

namespace Pre{
    pr mdf[MAXN*3]; int tot;
    struct BIT{
        int t[MAXN];
        void init(){fill(t+1,t+1+n,INF);}
        void mdf(int x,int v){x=n-x+1;for(;x<=n;x+=lowbit(x))tomin(t[x],v);}
        int qry(int x,int S=INF){x=n-x+1;for(;x;x-=lowbit(x))tomin(S,t[x]);return S;}
    }bit;
    void solve(){
        for(int i=1;i<=n;i++)mdf[++tot] = {x[i],i};
        for(int i=1;i<=m;i++)mdf[++tot] = {mx[i],i+n},mdf[++tot] = {qx[i],i+n+m};
        sort(mdf+1,mdf+1+tot);
        bit.init();
        for(int r=tot,l;r>=1;r=l-1){
            l=r; while(l>1 && mdf[l-1][0] == mdf[l][0])l--;
            for(int j=l;j<=r;j++)if(mdf[j][1] > n && mdf[j][1] <= n+m){
                int id = mdf[j][1] - n;
                bit.mdf(my[id],id);
            }
            for(int j=l;j<=r;j++){
                int id = mdf[j][1];
                if(id <= n){
                    mt[id] = bit.qry(y[id]);
                    if(mt[id] != INF)ap[mt[id]].push_back(id);
                }else if(id > n+m)id -= n+m,qt[id] = bit.qry(qy[id]);
            }
        }
    }
}
namespace DS{
    mt19937 rnd(0);
    struct Node{
        int lc,rc,sz,key;
        int vx,vy,tx,ty;
        Node(){key = rnd(),tx = ty = -1;}
    }t[MAXN]; int tot,rt;
    void pu(int x){ t[x].sz = t[lc(x)].sz + 1 + t[rc(x)].sz; }
    void cx(int x,int v){if(!x)return; t[x].vx = t[x].tx = v;}
    void cy(int x,int v){if(!x)return; t[x].vy = t[x].ty = v;}
    void pd(int x){
        if(t[x].tx != -1)cx(lc(x),t[x].tx),cx(rc(x),t[x].tx),t[x].tx = -1;
        if(t[x].ty != -1)cy(lc(x),t[x].ty),cy(rc(x),t[x].ty),t[x].ty = -1;
    }
    int cn(int x,int y){
        tot++;
        t[tot].vx = x,t[tot].vy = y,t[tot].sz = 1;
        return tot;
    }
    //
    int merge(int x,int y){
        if(!x || !y)return x+y;
        pd(x); pd(y);
        if(t[x].key > t[y].key){
            rc(x) = merge(rc(x),y);
            return pu(x),x;
        }else{
            lc(y) = merge(x,lc(y));
            return pu(y),y;
        }
    }
    void split(int u,int limx,int limy,int& x,int& y){
        if(!u)return void(x=y=0);
        pd(u);
        if(t[u].vx <= limx && t[u].vy >= limy){
            x = u;
            split(rc(x),limx,limy,rc(x),y);
        }else{
            y = u;
            split(lc(y),limx,limy,x,lc(y));
        }
        pu(u);
    }
    //
    void insert(int x,int y){
        int a = 0,b = cn(x,y),c = 0;
        split(rt,x,y,a,c);
        rt = merge(merge(a,b),c);
    }    
    void preget(int x,int y,int& a,int& b,int& c){
        split(rt,INF,y+1,a,b);
        split(b,x,0,b,c);
    }
    int qry(int x,int y){
        int a = 0,b = 0,c = 0;
        preget(x,y,a,b,c);
        int ans = t[b].sz;
        rt = merge(merge(a,b),c);
        return ans;
    }
    void mdf(int o,int x,int y){
        int a = 0,b = 0,c = 0;
        preget(x,y,a,b,c); 
        if(o == 1)cy(b,y); else cx(b,x);
        rt = merge(merge(a,b),c);
    }
}

pr mdf[MAXN*2]; int tot;

int main(){
    gi(n); gi(m);
    for(int i=1;i<=n;i++)gi(x[i]),gi(y[i]),tx.mdf(x[i],1),ty.mdf(y[i],1);
    for(int i=1;i<=m;i++){
        gi(o[i]); gi(mx[i]); gi(my[i]); gi(qx[i]); gi(qy[i]);
    }
    Pre::solve();
    for(int i=1,A=n;i<=m;i++){  
        DS::mdf(o[i],mx[i],my[i]);

        for(auto id : ap[i]){
            tx.mdf(x[id],-1),ty.mdf(y[id],-1); A--; 
            if(o[i] == 1)DS::insert(x[id],my[i]);
            else DS::insert(mx[i],y[id]);
        }   
        //
        ans[i] = DS::qry(qx[i],qy[i]);
        if(qt[i] <= i)continue; 
        ans[i] += A; ans[i] -= tx.qry(qx[i]+1) + ty.qry(qy[i]+1);
        mdf[++tot] = {qx[i]+1,i+m};
    }
    for(int i=1;i<=n;i++)mdf[++tot] = {x[i],i};
    sort(mdf+1,mdf+1+tot);
    for(int r=tot,l;r>=1;r=l-1){
        l=r; while(l>1 && mdf[l-1][0] == mdf[l][0])l--;
        for(int j=l;j<=r;j++)if(mdf[j][1] <= n){
            int id = mdf[j][1];
            tz.mdf(y[id],1);
        }
        for(int j=l;j<=r;j++)if(mdf[j][1] > n){
            int id = mdf[j][1]-n;
            ans[id] += tz.qry(qy[id]+1);
        }
    }
    for(int i=1;i<=m;i++)print(ans[i]),pc('\n');
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 87668kb

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:

325
485
803
165
791
95
243
787
834
194
243
373
508
-173
370
641
873
793
734
-165
720
437
-190
948
-247
-64
165
989
480
497
352
738
459
713
111
91
352
-275
736
147
313
609
147
948
308
653
981
685
-151
22
35
917
226
431
312
397
397
-253
424
538
-559
838
-718
536
667
122
-465
581
-87
633
744
559
415
68...

result:

wrong answer 1st numbers differ - expected: '423', found: '325'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 20
Accepted
time: 1617ms
memory: 156020kb

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
512663
0
0
0
0
407467
0
0
0
0
420
0
0
0
0
0
0
513245
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
349438
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
8602
0
0
0
0
0
0
0
15717
0
0
0
0
0
0
0
0
0
0...

result:

ok 999996 numbers

Test #10:

score: 0
Wrong Answer
time: 1901ms
memory: 153732kb

input:

999999 999998
593840 81071
226822 360556
984658 495723
774168 212723
961202 460976
425364 312068
135686 76747
312878 654073
77701 260718
263549 822714
513429 976716
926207 374094
338002 624578
897648 332005
630931 241967
134312 551284
743455 355739
997122 435568
642662 63663
795243 94444
696789 3776...

output:

490327
130567
57378
392376
32187
200032
0
0
571000
-12886
0
31925
279981
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
0
0
0
0
0
34171
18641
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
0
0
0
0
0
0
0
174097
-9845
0
0
0
0
0
0
0
0
0
0
0
20794
58166
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 1st numbers differ - expected: '491984', found: '490327'

Subtask #3:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 3903ms
memory: 168264kb

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:

132024
608721
-261757
341770
462111
297052
691803
-662277
171670
359549
116985
639781
906958
54680
258383
671903
185125
247717
791368
721946
594155
639501
437293
638325
-355713
471961
796158
23084
516399
289563
775101
481115
462412
148171
504529
790956
822202
329984
81815
-519944
641321
223844
54357...

result:

wrong answer 1st numbers differ - expected: '160635', found: '132024'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%