QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#557500#8672. 排队-xcxxx-0 237ms58036kbC++143.0kb2024-09-11 09:59:442024-09-11 09:59:45

Judging History

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

  • [2024-09-11 09:59:45]
  • 评测
  • 测评结果:0
  • 用时:237ms
  • 内存:58036kb
  • [2024-09-11 09:59:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int rd() {int x=0,f=1;char c=getchar();while(!isdigit(c))f=(c=='-'?-1:f),c=getchar();while(isdigit(c))x=x*10+c-'0',c=getchar();return x*f;}
const int N=1000005,inf=0x3f3f3f3f;
int n,Q,l[N],r[N],ans[N];
vector<int> ins[N],ers[N];
struct ChristmasTree {
    #define ls (p<<1)
    #define rs (p<<1|1)
    #define mid ((T[p].l+T[p].r)>>1)
    struct node {
        int l,r,mx,mn,tag;
        void upd(int x) {mx+=x,mn+=x,tag+=x;}
    }T[N<<2];
    void pushup(int p) {
        T[p].mx=max(T[ls].mx,T[rs].mx);
        T[p].mn=min(T[ls].mn,T[rs].mn);
    }
    void pushdown(int p) {
        T[ls].upd(T[p].tag);
        T[rs].upd(T[p].tag);
        T[p].tag=0;
    }
    void build(int l=1,int r=Q,int p=1) {
        T[p].l=l,T[p].r=r;
        T[p].mx=-inf,T[p].mn=inf;
        if(l==r) return;
        build(l,mid,ls);
        build(mid+1,r,rs);
    }
    void modify(int l,int r,int p=1) {
        if(T[p].l==l&&T[p].r==r) {
            T[p].upd(1);
            return;
        }
        pushdown(p);
        if(r<=mid) modify(l,mid,ls);
        else if(mid<l) modify(mid+1,r,rs);
        else modify(l,mid,ls),modify(mid+1,r,rs);
        pushup(p);
    }
    int qfst(int l,int r,int k,int p=1) {
        if(l==r) return l;
        pushdown(p);
        if(T[ls].mn<=k) return qfst(l,mid,k,ls);
        else return qfst(mid+1,r,k,rs);
    }
    int qlst(int l,int r,int k,int p=1) {
        if(l==r) return l;
        pushdown(p);
        if(T[rs].mx>=k) return qlst(mid+1,r,k,rs);
        else return qlst(l,mid,k,ls);
    }
    void insert(int pos,int p=1) {
        // fprintf(stderr,"insert [%d,%d] %d\n",T[p].l,T[p].r,pos);
        if(T[p].l==T[p].r) {
            T[p].mx=T[p].mn=0;
            return;
        }
        pushdown(p);
        if(pos<=mid) insert(pos,ls);
        else insert(pos,rs);
        pushup(p);
    }
    void erase(int pos,int p=1) {
        // fprintf(stderr,"erase [%d,%d] %d\n",T[p].l,T[p].r,pos);
        if(T[p].l==T[p].r) {
            T[p].mx=-inf,T[p].mn=inf;
            return;
        }
        pushdown(p);
        if(pos<=mid) erase(pos,ls);
        else erase(pos,rs);
        pushup(p);
    }
    int ask(int pos,int p=1) {
        if(T[p].l==T[p].r) return T[p].mx;
        pushdown(p);
        if(pos<=mid) return ask(pos,ls);
        else return ask(pos,rs);
    }
}tree;
signed main() {
    n=rd(),Q=rd();
    for(int i=1;i<=n;i++) l[i]=rd(),r[i]=rd();
    for(int i=1;i<=Q;i++) ins[rd()].push_back(i),ers[rd()].push_back(i);
    tree.build();
    for(int i=1;i<=n;i++) {
        // fprintf(stderr,"i=%d\n",i);
        for(int p:ins[i]) tree.insert(p);
        int L=tree.qfst(1,n,r[i]),R=tree.qlst(1,n,l[i]);
        tree.modify(L,R);
        for(int j=1;j<=4*Q;j++) tree.pushdown(j);
        for(int p:ers[i]) {
            ans[p]=tree.ask(p);
            tree.erase(p);
        }
    }
    for(int i=1;i<=Q;i++) printf("%d\n",ans[i]);
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 7ms
memory: 57076kb

input:

3 3
0 0
1 2
0 2
1 1
1 3
2 3

output:

1
3
1

result:

ok 3 number(s): "1 3 1"

Test #2:

score: 0
Wrong Answer
time: 237ms
memory: 58036kb

input:

5000 5000
5 10
3 9
3 8
2 7
2 5
3 6
1 5
0 2
7 8
2 10
0 3
3 6
4 6
1 6
4 8
7 8
2 7
3 4
4 9
7 8
2 9
2 5
3 6
0 5
6 7
1 2
2 4
2 10
1 5
7 9
6 9
2 3
9 10
5 5
2 9
3 3
2 7
2 4
0 6
0 3
1 7
7 7
4 8
2 9
4 8
0 10
1 8
1 1
2 7
5 9
1 7
1 7
1 4
2 4
1 4
2 9
1 7
4 7
3 8
1 3
4 6
1 5
1 6
0 0
3 9
4 7
2 8
1 8
1 2
7 8
2 7
2...

output:

11
11
22
11
11
33
99
77
22
11
55
22
168
25
66
33
77
135
179
99
66
22
238
273
65
146
11
11
233
362
328
107
139
33
106
193
11
144
270
86
28
343
55
542
421
22
404
192
337
266
108
55
286
226
206
289
281
70
417
110
471
613
224
99
321
562
383
429
189
406
24
310
350
248
398
285
22
166
38
852
804
46
437
184...

result:

wrong answer 3rd numbers differ - expected: '11', found: '22'

Subtask #2:

score: 0
Time Limit Exceeded

Test #12:

score: 0
Time Limit Exceeded

input:

200000 200000
3 6
3 3
6 10
1 7
2 7
6 9
4 6
3 4
0 8
0 6
3 5
3 4
1 8
7 8
4 5
0 3
1 5
2 9
1 2
1 2
3 4
5 7
6 10
3 9
4 7
1 6
2 6
1 7
2 5
1 7
6 8
1 1
0 7
7 8
0 9
1 7
3 8
3 7
1 2
4 8
5 6
0 6
5 6
2 7
2 6
0 6
0 6
1 7
2 5
0 3
0 3
7 10
3 8
0 2
3 4
3 7
4 9
0 6
4 7
2 6
8 10
2 10
4 10
3 3
2 6
4 5
3 9
1 8
1 2
2 9
...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #22:

score: 0
Time Limit Exceeded

input:

200000 200000
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 0
0 9
0 10
0 0
0 0
0 13
0 14
0 0
0 16
0 17
0 18
0 19
0 0
0 21
0 22
0 23
0 0
0 0
0 0
0 0
0 28
0 0
0 30
0 31
0 32
0 33
0 34
0 35
0 0
0 0
0 38
0 39
0 40
0 41
0 42
0 43
0 44
0 45
0 46
0 0
0 48
0 49
0 50
0 51
0 52
0 53
0 54
0 55
0 56
0 57
0 0
0 59
0 60
0 0
0 0
...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #32:

score: 0
Time Limit Exceeded

input:

200000 200000
0 200000
1 200000
1 200000
0 200000
0 200000
1 200000
1 200000
1 200000
0 200000
1 200000
0 200000
0 200000
1 200000
0 200000
0 200000
0 200000
0 200000
1 200000
0 200000
0 200000
1 200000
0 200000
1 200000
1 200000
1 200000
1 200000
0 200000
0 200000
1 200000
2 200000
1 200000
2 20000...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%