QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#413170#8672. 排队cz_yxx0 97ms28944kbC++203.9kb2024-05-17 09:13:002024-05-17 09:13:01

Judging History

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

  • [2024-05-17 09:13:01]
  • 评测
  • 测评结果:0
  • 用时:97ms
  • 内存:28944kb
  • [2024-05-17 09:13:00]
  • 提交

answer

//私は猫です
#include <bits/stdc++.h>
using namespace std;
// #define int long long
int read(){
    int xx = 0, f = 1; char ch = getchar();
    for (;!isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (; isdigit(ch); ch = getchar())
        xx = (xx << 3) + (xx << 1) + ch - '0';
    return xx * f;
}
const int N = 1000100, inf = 1e9 + 7;
struct sqtr{
    int ans[N << 2], ll[N << 2], rr[N << 2], sub[N << 2];
    bool fl;
    void up(int x){
        ll[x] = min(ll[x << 1], ll[x << 1 | 1]),
        rr[x] = min(rr[x << 1], rr[x << 1 | 1]);
    }
    void dec(int x, int val){
        ll[x] -= val, rr[x] -= val, sub[x] += val;
    }
    void dw(int x){
        if (ans[x] != 0)
            ans[x << 1] += ans[x], ans[x << 1 | 1] += ans[x],
            ans[x] = 0;
        if (sub[x] != 0)
            dec(x << 1, sub[x]), dec(x << 1 | 1, sub[x]),
            sub[x] = 0;
    }
    void upd(int x, int l, int r, int nl, int val, int var){
        if (l == r){
            ll[x] = val, rr[x] = var, ans[x] = 0; return ;
        }
        int mid = (l + r) >> 1; dw(x);
        if (nl <= mid)upd(x << 1, l, mid, nl, val, var);
        else upd(x << 1 | 1, mid + 1, r, nl, val, var);
        up(x);
    }
    void work(int x, int l, int r, int &val){
        if (ll[x] - val > 0 && rr[x] - val >= 0){
            dec(x, val), ans[x] += val; return ;
        }
        if (l == r){
            int ad = 0;
            if (ll[x] - val <= 0)ll[x] = inf, ++ad;
            if (rr[x] - val < 0)rr[x] = inf, --ad;
            val += ad;
            ans[x] += val;
            return ;
        }
        int mid = (l + r) >> 1; dw(x);
        work(x << 1, l, mid, val), work(x << 1 | 1, mid + 1, r, val);
        up(x);
    }
    void mdy(int x, int l, int r, int nl, int &val){
        if (nl > r)return ;
        if (nl <= l){
            if (ll[x] - val <= 0 || rr[x] - val < 0)work(x, l, r, val);
            else dec(x, val);
            if (val == 0){fl = true; return ;}
            return ;
        }
        int mid = (l + r) >> 1;
        if (nl <= mid){
            mdy(x << 1, l, mid, nl, val);
            if (!fl)mdy(x << 1 | 1, mid + 1, r, nl, val);
        }
        else mdy(x << 1 | 1, mid + 1, r, nl, val);
    }
    void add(int x, int l, int r, int nl, int nr){
        if (nl > nr)return ;
        if (nl <= l && r <= nr){++ans[x]; return ;}
        int mid = (l + r) >> 1; dw(x);
        if (nl <= mid)add(x << 1, l, mid, nl, nr);
        if (nr > mid)add(x << 1 | 1, mid + 1, r, nl, nr);
    }
    int query(int x, int l, int r, int nl){
        if (l == r){return ans[x];}
        int mid = (l + r) >> 1; dw(x);
        if (nl <= mid)return query(x << 1, l, mid, nl);
        else return query(x << 1 | 1, mid + 1, r, nl);
    }
    void out(int x, int l, int r){
        if (l == r){cout<<ans[x]<<" "; return ;}
        int mid = (l + r) >> 1; dw(x);
        out(x << 1, l, mid), out(x << 1 | 1, mid + 1, r);
    }
    void build(int x, int l, int r){
        ans[x] = 0;
        if (l == r)return ;
        int mid = (l + r) >> 1;
        build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r);
    }
}A;
int n, q, l[N], r[N], ans[N];
struct Q{
    int l, r, id;
}qu[N];
bool cmp(Q x, Q y){return x.l > y.l;}
signed main(){
    n = read(), q = read();
    for (int i = 1; i <= n; ++i)l[i] = read(), r[i] = read();
    for (int i = 1, x, y; i <= q; ++i)x = read(), y = read(), qu[i] = Q{x, y, i};
    sort(qu + 1, qu + q + 1, cmp);
    A.build(1, 1, n);
    for (int i = n, j = 1, va; i >= 1; --i){
        A.upd(1, 1, n, i, l[i], r[i]);
        A.fl = false, va = 0, A.mdy(1, 1, n, i, va);
        // A.out(1, 1, n); printf("\n");
        while(j <= q && qu[j].l == i)ans[qu[j].id] = A.query(1, 1, n, qu[j].r), ++j;
    }
    for (int i = 1; i <= q; ++i)printf("%d\n", ans[i]);
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 0ms
memory: 15896kb

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: 5ms
memory: 16204kb

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:

16
18
20
17
15
18
20
15
16
17
18
17
16
17
18
20
13
20
17
17
13
16
18
20
16
17
16
14
17
19
17
17
17
15
16
18
14
16
15
17
18
16
13
18
20
14
19
14
16
17
17
17
19
19
19
15
17
14
17
19
19
19
19
15
16
15
18
19
17
17
14
18
16
15
18
16
17
18
15
13
15
16
18
18
13
18
15
16
16
14
15
17
18
16
18
18
15
16
13
17
...

result:

wrong answer 1st numbers differ - expected: '11', found: '16'

Subtask #2:

score: 0
Wrong Answer

Test #12:

score: 0
Wrong Answer
time: 79ms
memory: 28944kb

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:

18
19
16
20
18
18
15
17
18
19
18
17
18
19
21
21
17
17
20
18
19
16
18
15
15
17
16
19
18
19
19
19
20
20
16
18
18
17
17
19
21
19
17
17
18
16
18
20
15
16
19
18
18
20
20
16
20
20
19
18
20
15
18
19
19
20
13
18
21
20
17
16
19
20
16
17
19
19
16
16
18
18
15
15
21
15
19
17
18
14
18
19
19
19
20
17
18
20
19
14
...

result:

wrong answer 1st numbers differ - expected: '11', found: '18'

Subtask #3:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 97ms
memory: 28336kb

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:

7
4
7
8
5
3
4
7
2
5
7
7
4
4
5
8
6
5
7
6
7
3
7
6
6
3
6
5
10
7
4
9
5
6
6
5
8
9
7
6
6
6
5
10
2
8
9
5
7
5
7
4
5
6
7
5
7
2
6
6
7
6
4
6
10
6
5
8
5
5
6
6
10
6
7
5
7
10
4
4
6
6
7
7
7
5
6
7
6
7
6
4
6
8
6
6
5
6
5
8
6
8
6
3
2
7
7
5
6
7
6
7
5
6
5
5
5
5
7
6
7
7
4
3
7
9
7
5
6
7
8
6
4
7
5
7
5
7
7
6
6
6
3
7
7
9
3
9...

result:

wrong answer 1st numbers differ - expected: '19141', found: '7'

Subtask #4:

score: 0
Wrong Answer

Test #32:

score: 0
Wrong Answer
time: 96ms
memory: 26880kb

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:

23
15
41
28
3
19
21
19
25
31
27
27
29
42
40
27
28
33
16
27
31
30
20
15
25
12
23
19
10
16
9
24
41
23
24
30
33
8
15
26
22
29
25
13
22
24
31
33
35
23
21
20
22
21
14
21
27
18
13
22
16
14
28
16
13
26
31
10
26
12
29
41
14
23
25
25
15
33
16
45
18
21
16
36
21
13
30
17
20
21
37
25
11
46
16
18
30
18
25
20
28
...

result:

wrong answer 1st numbers differ - expected: '71224', found: '23'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%