Submission #745118

# Submission time Handle Problem Language Result Execution time Memory
745118 2023-05-19T12:14:12 Z Itamar Street Lamps (APIO19_street_lamps) C++14
20 / 100
431 ms 524288 KB
#include <iostream>
using namespace std;
#include<bitset>
#include<vector>
#define vi vector<int>

int main()
{
    int n, q;
    cin >> n >> q;
    const int siz = 3e5;
    bitset<siz> b;
    string s;
    cin >> s;
    vector<vi> ans(n,vi(n));
    for (int i = 0; i < n; i++)b[i] = (s[i] == '1');
    for (int i = 1; i <= q; i++) {
        string st;
        cin >> st;
        if (st == "toggle") {
            int in;
            cin >> in;
            in--;
            if (b[in]) {
                int x = in, y = in;
                while (x>=0&&b[x])x--;
                while (y<=n-1&&b[y])y++;
                x++, y--;
                for (int j = x; j <= in; j++) {
                    for (int k = in; k <= y; k++) {
                        ans[j][k] += i;
                    }
                }
                    b[in] = 0;
            }
            else {
                b[in] = 1;
                int x = in, y = in;
                while (x>=0&&b[x])x--;
                while (y<=n-1&&b[y])y++;
                x++, y--;
                //ans(x,in,in,y)-=i;
                for (int j = x; j <= in; j++) {
                    for (int k = in; k <= y; k++) {
                        ans[j][k] -= i;
                    }
                }
                /*for (int j = x; j <= in - 1; j++) {
                    for (int k = x; k <= in - 1; k++) {
                        ans[j][k] += i;
                    }
                }
                for (int j = in + 1; j <= y; j++) {
                    for (int k = in + 1; k <= y; k++) {
                        ans[j][k] += i;
                    }
                }*/
            }
        }
        else {
            int x, y;
            cin >> x >> y;
            x--, y -= 2;
            bool f = 1;
            for (int i = x; i <= y; i++)if (b[i] == 0)f = 0;
            cout << ans[x][y] + i *f << "\n";
        }
    }
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 343 ms 4352 KB Output is correct
2 Correct 353 ms 1612 KB Output is correct
3 Correct 431 ms 99236 KB Output is correct
4 Runtime error 185 ms 524288 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 4 ms 4180 KB Output is correct
3 Correct 4 ms 4180 KB Output is correct
4 Correct 4 ms 4180 KB Output is correct
5 Runtime error 185 ms 524288 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4308 KB Output is correct
2 Correct 3 ms 4288 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 3 ms 4180 KB Output is correct
5 Runtime error 182 ms 524288 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 343 ms 4352 KB Output is correct
9 Correct 353 ms 1612 KB Output is correct
10 Correct 431 ms 99236 KB Output is correct
11 Runtime error 185 ms 524288 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -