QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527748#7436. Optimal Ordered Problem SolverCrying0 3824ms199156kbC++144.5kb2024-08-22 19:02:072024-08-22 19:02:07

Judging History

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

  • [2024-08-22 19:02:07]
  • 评测
  • 测评结果:0
  • 用时:3824ms
  • 内存:199156kb
  • [2024-08-22 19:02:07]
  • 提交

answer

#include<bits/stdc++.h>
#define lc(x) (t[x].lc)
#define rc(x) (t[x].rc)
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;
typedef vector<int> vec; 
typedef array<int,2> pr;
typedef array<int,4> qr; //(x,y,type,id)
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{
    qr 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] = (qr){x[i],y[i],1,i};
        for(int i=1;i<=m;i++)mdf[++tot] = (qr){mx[i],my[i],3,i},mdf[++tot] = (qr){qx[i],qy[i],2,i};
        sort(mdf+1,mdf+1+tot);
        bit.init();
        for(int i=tot;i>=1;i--){
            qr& now = mdf[i]; int id = now[3],type = now[2],y = now[1];
            if(type == 3)bit.mdf(y,id);
            else if(type == 1){
                mt[id] = bit.qry(y);
                if(mt[id] != INF)ap[mt[id]].push_back(id);
            }else qt[id] = bit.qry(y);
        }
    }
}
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,0,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);
    }
}

qr mdf[MAXN*2]; int tot;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);

    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>x[i]>>y[i],tx.mdf(x[i],1),ty.mdf(y[i],1);
    for(int i=1;i<=m;i++)cin>>o[i]>>mx[i]>>my[i]>>qx[i]>>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,qy[i]+1,1,i};
    }
    for(int i=1;i<=n;i++)mdf[++tot] = {x[i],y[i],2,-1};
    sort(mdf+1,mdf+1+tot);
    for(int i=tot;i>=1;i--){
        qr& now = mdf[i]; int y = now[1],type = now[2],id = now[3];
        if(type==2)tz.mdf(y,1);
        else ans[id] += tz.qry(y);
    }
    for(int i=1;i<=m;i++)cout<<ans[i]<<"\n";
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 16ms
memory: 83520kb

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
1
144
974
526
415
439
694
507
577
258
120
243
9
8
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
38
0
178
625
677
561
488
672
577
64
144
537
235
62...

result:

wrong answer 26th numbers differ - expected: '3', found: '1'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 2064ms
memory: 182908kb

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
75465
953730
30210
22420
859562
0
10997
1901
0
776333
0
0
0
0
883717
0
0
0
0
0
0
878809
0
876833
0
49
49
49
49
49
49
49
0
896479
0
808528
892545
1426
0
0
0
907449
0
0
0
892956
0
0
0
0
0
0
0
0
0
0
1426
807728
0
0
0
0
0
898541
1351
0
0
0
805213
0
0
891526
1426
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
7...

result:

wrong answer 2nd numbers differ - expected: '0', found: '75465'

Subtask #3:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 3824ms
memory: 199156kb

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:

160637
633545
123521
313579
450015
383638
574188
2378
203701
326075
117994
567277
652826
199783
380319
380379
105882
373861
788346
703180
609805
648165
367068
497984
57988
478851
745058
75945
543070
251847
769828
436497
480976
235845
509633
757192
763494
396852
262688
2255
267186
165795
558973
16525...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%