답안 #977795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977795 2024-05-08T11:10:59 Z ZHIRDILBILDIZ 가로등 (APIO19_street_lamps) C++14
40 / 100
138 ms 32504 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>

using namespace std;

signed main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int t = 1;
    while (t--) {
        int n, q;
        cin >> n >> q;
        char a[n + 1];
        for (int i = 1; i <= n; ++i)
            cin >> a[i];
        bool sub2 = 1;
        string type[q + 1];
        int c[q + 1], d[q + 1];
        bool abu[q + 1] = {};
        for (int i = 1; i <= q; ++i) {
            cin >> type[i] >> c[i];
            if (type[i] == "query") {
                cin >> d[i];
                abu[i] = 1;
                if (d[i] - c[i] != 1)
                    sub2 = 0;
            }
        }

        if (sub2) {
            int ans[q + 1] = {};
            vector<pair<bool, int>> query[n + 1];

            for (int i = 1; i <= q; ++i)
                if (type[i] == "toggle")
                    query[c[i]].push_back({0, i});
                else
                    query[c[i]].push_back({1, i});

            for (int i = 1; i <= n; ++i) {
                pair<char, int> now = {a[i], 0};
                int cnt = 0;
                now = {a[i], 0};
                for (auto j : query[i]) {
                    if (j.fi) {
                        ans[j.se] = cnt + (now.fi == '1') * (j.se - now.se);
                    } else {
                        if (now.fi == '1') {
                            cnt += (j.se - now.se);
                            now.fi = '0';
                        } else {
                            now.fi = '1';
                        }
                        now.se = j.se;
                    }
                }
            }
            for (int i = 1; i <= q; ++i) {
                // cout << "i = " << i <<" ";
                if (abu[i])
                    cout << ans[i] << '\n';
            }
            continue;
        }

        if (n <= 100 && q <= 100) {
            bool b[n + 1][q + 1] = {};
            for (int j = 1; j <= n; ++j)
                b[j][0] = a[j] - '0';
            for (int i = 1; i <= q; ++i) {
                if (type[i] == "toggle") {
                    if (a[c[i]] == '1')
                        a[c[i]] = '0';
                    else
                        a[c[i]] = '1';
                }
                for (int j = 1; j <= n; ++j)
                    b[j][i] = a[j] - '0';
                if (type[i] == "query") {
                    int ans = 0;
                    for (int j = 0; j < i; ++j) {
                        bool flag = 1;
                        for (int z = c[i]; z < d[i]; ++z)
                            flag &= (b[z][j]);
                        ans += flag;
                    }
                    cout << ans << '\n';
                }
            }
            continue;
        }

    }

    return 0;
}

// 10 5
// 1101110100
// query 1 2
// toggle 1
// query 2 3
// toggle 1
// query 1 2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 17604 KB Output is correct
2 Correct 77 ms 20048 KB Output is correct
3 Correct 78 ms 20760 KB Output is correct
4 Correct 105 ms 31060 KB Output is correct
5 Correct 118 ms 31568 KB Output is correct
6 Correct 132 ms 30920 KB Output is correct
7 Correct 125 ms 31160 KB Output is correct
8 Correct 138 ms 32504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 75 ms 17604 KB Output is correct
9 Correct 77 ms 20048 KB Output is correct
10 Correct 78 ms 20760 KB Output is correct
11 Correct 105 ms 31060 KB Output is correct
12 Correct 118 ms 31568 KB Output is correct
13 Correct 132 ms 30920 KB Output is correct
14 Correct 125 ms 31160 KB Output is correct
15 Correct 138 ms 32504 KB Output is correct
16 Incorrect 1 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -