QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#531661 | #186. Street Lamps | isirazeev | 0 | 1597ms | 7728kb | C++20 | 3.1kb | 2024-08-24 21:33:40 | 2024-08-24 21:33:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<pair<int, int>, int> F;
void add(int x, int y, int val) {
int st = y;
while (x > 0) {
y = st;
while (y > 0) {
F[{x, y}] += val;
y -= (y & (-y));
}
x -= (x & (-x));
}
}
void add(int l1, int r1, int l2, int r2, int val) {
add(l2, 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[{x, 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;
}
}
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++) {
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, i);
}
s[ind] = char(1 - (s[ind] - '0') + '0');
} else {
int a, b;
cin >> a >> b;
bool f = false;
for (int j = a; j < b; j++) {
if (s[j] == '0') f = true;
}
int res = get(a, b);
if (!f) res += i;
cout << res << "\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 20
Accepted
time: 0ms
memory: 5932kb
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: 2ms
memory: 5876kb
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 1 3 0 4 -7 0 9 -7 0 5 -7 -7 5 -7 5 -13 -3 0 -106 0 -7 0 -7 -23
result:
wrong answer 3rd lines differ - expected: '7', found: '3'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 1597ms
memory: 6320kb
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 0 0 14 0 18 0 0 21 0 26 0 0 12 38 15 16 44 0 22 20 50 28 0 55 52 56 0 78 31 70 45 7 4 0 0 51 83 -1 90 37 0 95 97 0 70 0 88 26 8 46 -67 0 88 -67 0 108 0 0 -58 0 135 114 53 78 142 44 146 0 8 0 138 0 0 -34 0 164 0 100 0 -104 -65 135 42 178 180 51 133 -49 89 0 197 23 0 200 0 141 206 208 -6...
result:
wrong answer 8th lines differ - expected: '7', found: '0'
Subtask #3:
score: 0
Time Limit Exceeded
Test #17:
score: 20
Accepted
time: 9ms
memory: 6804kb
input:
1000 1003 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
0 0 0
result:
ok 3 lines
Test #18:
score: 20
Accepted
time: 12ms
memory: 7700kb
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: 10ms
memory: 7616kb
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: 14ms
memory: 7628kb
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:
result:
Subtask #4:
score: 0
Wrong Answer
Test #30:
score: 20
Accepted
time: 10ms
memory: 7668kb
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: 13ms
memory: 7728kb
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: '0'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%