QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#531751#186. Street Lampsisirazeev0 483ms6688kbC++203.4kb2024-08-24 22:02:182024-08-24 22:02:20

Judging History

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

  • [2024-08-24 22:02:20]
  • 评测
  • 测评结果:0
  • 用时:483ms
  • 内存:6688kb
  • [2024-08-24 22:02:18]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

unordered_map<long long, int> F;

void add(int x, int y, int val) {
    int st = y;
    while (x > 0) {
        y = st;
        while (y > 0) {
            F[(long long) x * (long long) 1e9 + y] += val;
            y -= (y & (-y));
        }
        x -= (x & (-x));
    }
}

void add(int l1, int r1, int l2, int r2, int val) {
    add(r1, r2, val);
    add(l1 - 1, r2, -val);
    add(r1, l2 - 1, -val);
    add(l1 - 1, l2 - 1, val);
}

const int N = (int) 1e5 * 3 + 10;

int get(int x, int y) {
    int res = 0, st = y;
    while (x < N) {
        y = st;
        while (y < N) {
            res += F[(long long) x * (long long) 1e9 + y];
            y += (y & (-y));
        }
        x += (x & (-x));
    }
    return res;
}

set<pair<int, int>> st;
int pr[N];

void insert(int val) {
    int L = val, R = val;
    if (pr[R + 1] != -1) {
        st.erase({R + 1, pr[R + 1]});
        R = pr[R + 1];
        pr[pr[R]] = -1;
    }
    if (L >= 1 && pr[L - 1] != -1) {
        st.erase({pr[L - 1], L - 1});
        L = pr[L - 1];
        pr[pr[L]] = -1;
    }
    st.insert({L, R});
    pr[L] = R, pr[R] = L;
}

void del(int val) {
    auto it = --st.lower_bound({val + 1, 0});
    int L = it->first, R = it->second;
    st.erase(it);
    pr[L] = pr[R] = -1;
    if (val - 1 >= L) {
        st.insert({L, val - 1});
        pr[L] = val - 1, pr[val - 1] = L;
    }
    if (val + 1 <= R) {
        st.insert({val + 1, R});
        pr[val + 1] = R, pr[R] = val + 1;
    }
}

int f[N];

void update(int i, int val) {
    for (; i < N; i += (i & (-i)))
        f[i] += val;
}

int sum(int r) {
    int res = 0;
    while (r > 0) {
        res += f[r];
        r -= (r & (-r));
    }
    return res;
}

int get_sum(int l, int r) {
    return sum(r) - sum(l - 1);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    for (int i = 0; i < N; i++) pr[i] = -1;
    int n, q, L = -1, R = -1;
    string t;
    cin >> n >> q >> t;
    string s = '#' + t;
    for (int i = 1; i <= n; i++) {
        update(i, s[i] - '0');
        if (s[i] == '0') {
            if (L != -1)
                st.insert({L, R});
            L = R = -1;
        } else {
            if (L == -1) L = R = i;
            else R++;
        }
    }
    if (L != -1) st.insert({L, R});
    for (auto [a, b]: st)
        pr[a] = b, pr[b] = a;
    for (int i = 1; i <= q; i++) {
        string type;
        cin >> type;
        if (type == "toggle") {
            int ind;
            cin >> ind;
            if (s[ind] == '0') {
                if (pr[ind - 1] != -1) L = pr[ind - 1];
                else L = ind;
                if (pr[ind + 1] != -1) R = pr[ind + 1];
                else R = ind;
                insert(ind);
                add(L, ind, ind + 1, R + 1, -i);
            } else {
                auto it = --st.lower_bound({ind + 1, 0});
                L = it->first, R = it->second;
                del(ind);
                add(L, ind, ind + 1, R + 1, i);
            }
            update(ind, 1 - (s[ind] - '0'));
            s[ind] = char(1 - (s[ind] - '0') + '0');
        } else {
            int a, b;
            cin >> a >> b;
            int res = get(a, b);
            if (get_sum(a, b - 1) == b - a) res += i;
            cout << res << "\n";
        }
    }
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 1ms
memory: 4744kb

input:

5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6

output:

1
2
0
0
1
2

result:

ok 6 lines

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 4872kb

input:

5 50
01001
query 1 6
toggle 3
toggle 3
toggle 2
toggle 3
toggle 2
toggle 4
query 2 6
query 2 3
query 1 3
query 3 5
toggle 3
query 2 6
query 1 5
query 2 3
query 3 6
toggle 5
toggle 1
toggle 2
toggle 4
query 1 6
query 4 5
toggle 3
query 5 6
toggle 2
query 4 6
toggle 5
toggle 5
toggle 2
query 4 5
query...

output:

0
-7
-2
10
-7
5
0
-2
5
0
35
41
36
43
5
5
-29
-18
0
-35
0
5
0
5
6

result:

wrong answer 2nd lines differ - expected: '1', found: '-7'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 483ms
memory: 5016kb

input:

100 300000
1100100000000101010010100111010001100010001100111101000010111110001101101110100100100110101010110010
query 13 14
query 42 43
toggle 64
query 78 79
toggle 85
query 35 36
toggle 35
query 4 5
toggle 5
query 4 5
query 42 43
query 35 36
query 13 14
query 14 15
toggle 15
toggle 31
query 20 21
q...

output:

0
0
0
6
0
0
0
19
0
14
0
18
0
0
21
0
26
0
0
36
38
15
41
44
0
47
20
50
52
0
55
52
56
0
100
31
70
73
7
4
0
0
51
83
84
90
-49
0
95
97
0
70
0
103
26
8
160
140
230
122
143
234
235
0
0
159
0
135
139
112
176
142
-92
146
0
151
0
153
0
0
73
0
164
0
269
0
205
173
-40
-25
178
180
75
133
189
-144
0
197
221
0
200...

result:

wrong answer 8th lines differ - expected: '7', found: '19'

Subtask #3:

score: 0
Time Limit Exceeded

Test #17:

score: 20
Accepted
time: 4ms
memory: 5156kb

input:

1000 1003
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0
0
0

result:

ok 3 lines

Test #18:

score: 20
Accepted
time: 5ms
memory: 6688kb

input:

1000 1003
00100001101000000001000001001000100010000010010010001001001010001010101100010001000010101100000001001111000001110000010110100000100110001000000101001110000001110001000100000011001110000011010100101000000010100110100010000000110000111100100000011000100010010100000000100000000010001001110101...

output:

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
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
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
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
...

result:

ok 304 lines

Test #19:

score: 20
Accepted
time: 0ms
memory: 5640kb

input:

1000 1003
11001001111000111100001101101111110010111101110100101000111001111011110111110111111001110011111110111110101110011101111111111111010111010100011010011100101011111001111010111110111010111011101100100111010000110101110001000011100010111110011001010110101111011101100110001100111000000011000111...

output:

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
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
0
0
0
0
0
0
0
0
70
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
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...

result:

ok 595 lines

Test #20:

score: 20
Accepted
time: 5ms
memory: 5936kb

input:

1000 1003
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

ok 1003 lines

Test #21:

score: 0
Time Limit Exceeded

input:

300000 300000
0000000000000000000000000000000000000000000000000100000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000...

output:

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
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
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
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
...

result:


Subtask #4:

score: 0
Wrong Answer

Test #30:

score: 20
Accepted
time: 0ms
memory: 5732kb

input:

1000 1003
10111011001010101101100010101100100010100110001000000001001100111110101100110100010001111101101100110111110100011000111101100100000110110010101011101001101110111100010100100000110001010001111101001010100101011111010000001110111110001011010111101100000001001110101110011111000101101100011010...

output:

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
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
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
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
...

result:

ok 991 lines

Test #31:

score: 0
Wrong Answer
time: 0ms
memory: 5960kb

input:

1000 1003
01000000111001001110011100111111110011010010110000100010101101101011100011010100100100110101110101010111011100110100110000001010110001011011011010001001101000111011001000000001001100101100010101011101000000101110111011011101100001011110111011001010011101000110100011000101011101000110001011...

output:

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
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
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
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
...

result:

wrong answer 550th lines differ - expected: '92', found: '944'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%