QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#531701 | #186. Street Lamps | isirazeev | 0 | 0ms | 3876kb | C++20 | 2.9kb | 2024-08-24 21:47:43 | 2024-08-24 21:47:44 |
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--;
}
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) 1e2 * 3 + 10;
int get(int x, int y) {
return F[{x, y}];
}
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 + 1, 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;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 20
Accepted
time: 0ms
memory: 3876kb
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: 0ms
memory: 3588kb
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 7 0 4 5 0 13 5 0 25 10 22 25 5 5 6 29 0 10 0 5 0 5 6
result:
wrong answer 11th lines differ - expected: '13', found: '25'
Subtask #2:
score: 0
Time Limit Exceeded
Test #9:
score: 0
Time Limit Exceeded
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 7 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 123 106 -1 90 44 0 95 97 0 70 0 154 26 8 46 20 109 88 20 109 108 0 0 28 0 135 174 53 78 142 53 146 0 8 0 204 0 0 -34 0 164 0 127 0 33 34 135 151 178 180 217 249 50 89 0 392 23 0 200 0 332 206 208 ...
result:
Subtask #3:
score: 0
Runtime Error
Test #17:
score: 0
Runtime Error
input:
1000 1003 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #30:
score: 0
Runtime Error
input:
1000 1003 10111011001010101101100010101100100010100110001000000001001100111110101100110100010001111101101100110111110100011000111101100100000110110010101011101001101110111100010100100000110001010001111101001010100101011111010000001110111110001011010111101100000001001110101110011111000101101100011010...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%