이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 105;
int n, q;
string s;
int f[N][N], cnt[N][N];
void on(int a, int b, int t) {
f[a][b] -= t;
cnt[a][b]++;
}
void off(int a, int b, int t) {
f[a][b] += t;
cnt[a][b]--;
}
void toggle(int i, int t) {
if (s[i] == '0') {
int p = i, q = i + 1;
while (p > 0 && s[p - 1] == '1') p--;
while (q < n && s[q] == '1') q++;
for (int a = p; a <= i; a++) {
for (int b = i + 1; b <= q; b++) {
on(a, b, t);
}
}
s[i] = '1';
} else {
int p = i, q = i + 1;
while (p > 0 && s[p - 1] == '1') p--;
while (q < n && s[q] == '1') q++;
for (int a = p; a <= i; a++) {
for (int b = i + 1; b <= q; b++) {
off(a, b, t);
}
}
s[i] = '0';
}
}
int query(int a, int b, int t) {
return f[a][b] + t * cnt[a][b];
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q >> s;
for (int i = 0; i < n; i++) {
bool ok = 1;
for (int j = i + 1; j <= n; j++) {
if (s[j - 1] == '0') break;
on(i, j, 0);
}
}
for (int t = 1; t <= q; t++) {
string type;
cin >> type;
if (type == "toggle") {
int i;
cin >> i;
i--;
toggle(i, t);
} else {
int a, b;
cin >> a >> b;
a--;
b--;
cout << query(a, b, t) << '\n';
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:59:14: warning: unused variable 'ok' [-Wunused-variable]
59 | bool ok = 1;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |