# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
916863 | duckindog | 가로등 (APIO19_street_lamps) | C++14 | 92 ms | 24752 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, q;
int a[N];
struct Query {
int ty, x, y;
Query() : ty(0), x(0), y(0) {}
Query(int ty, int x, int y) : ty(ty), x(x), y(y) {}
} Q[N];
string s[N];
void sub1() {
cin >> s[1];
for (int i = 1; i <= q; ++i) {
s[i + 1] = s[i];
string ty; cin >> ty;
if (ty == "toggle") {
int p; cin >> p;
s[i + 1][p - 1] = (s[i + 1][p - 1] == '0' ? '1' : '0');
} else {
int a, b; cin >> a >> b;
int answer = 0;
for (int j = 1; j <= i; ++j) {
bool pass = 1;
for (int t = a - 1; t < b - 1; ++t)
if (s[j][t] == '0') pass = 0;
answer += pass;
}
cout << answer << '\n';
}
}
}
int cnt[N], t[N];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
cin >> n >> q;
if (n <= 100 && q <= 100) {
sub1();
return 0;
}
for (int i = 1; i <= n; ++i) {
char x; cin >> x;
a[i] = (x == '1');
}
bool s2 = 1;
for (int i = 1; i <= q; ++i) {
string ty; cin >> ty;
if (ty == "toggle") {
int x; cin >> x;
Q[i] = {0, x, 0};
} else {
int x, y; cin >> x >> y;
Q[i] = {1, x, y};
s2 &= (y - x == 1);
}
}
if (s2) {
for (int i = 1; i <= n; ++i) {
t[i] = (a[i] == 1);
}
for (int i = 1; i <= q; ++i) {
int ty = Q[i].ty, x = Q[i].x, y = Q[i].y;
if (!ty) {
if (a[x] == 1) {
cnt[x] += i - t[x] + 1;
t[x] = i + 1;
} else {
t[x] = i + 1;
}
a[x] = 1 - a[x];
} else {
int answer = 0;
if (a[x]) {
answer = cnt[x] + i - t[x] + 1;
} else {
answer = cnt[x];
}
cout << answer << '\n';
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |