Submission #447474

# Submission time Handle Problem Language Result Execution time Memory
447474 2021-07-26T13:21:44 Z K4YAN Street Lamps (APIO19_street_lamps) C++17
20 / 100
5000 ms 12636 KB
//Be Name Khoda
// 06:10 - 13:15

#include<bits/stdc++.h>
#pragma GCC optimize ("unroll-loops")

using namespace std;

typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pll pair<ll, ll>
#define pii pair<int, int>
#define plll pair<pll, ll>
#define piii pair<pii, int>
#define piiii pair<pii, pii>

const int mxn = 1e5 + 16;
int n, q, v, u;
string s, h, cur;
vector<piii> qu;

void input() {

    cin >> n >> q;
    cin >> s;
    cur = s;
    for(int i = 0; i < q; i++) {
        cin >> h;
        if(h == "query") {
            cin >> v >> u;
            v--, u--;
            qu.push_back({{1, v}, u});
        }
        else {
            cin >> v;
            v--;
            qu.push_back({{2, v}, v});
        }
    }

}

void solve() {

    for(int i = 0; i < qu.size(); i++) {
        if(qu[i].first.first == 1) {
            int cnt = 0;
            cur = s;
            v = qu[i].first.second, u = qu[i].second;
            for(int j = 0; j <= i; j++) {
                bool b = true;
                for(int w = v; w < u; w++) {
                    if(cur[w] == '0') {
                        b = false;
                        break;
                    }
                }
                if(b) {
                    cnt++;
                }
                if(qu[j].first.first == 2) {
                    if(cur[qu[j].second] == '1') cur[qu[j].second] = '0';
                    else {
                        cur[qu[j].second] = '1';
                    }
                }
            }
            cout << cnt << endl;
        }
    }

}

int main() {

    ios_base::sync_with_stdio(false);

    input(), solve();

    return 0;

}
/*
5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6
*/

Compilation message

street_lamps.cpp: In function 'void solve()':
street_lamps.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i = 0; i < qu.size(); i++) {
      |                    ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5049 ms 9632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 55 ms 332 KB Output is correct
5 Correct 3515 ms 11100 KB Output is correct
6 Execution timed out 5087 ms 11600 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 5 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Execution timed out 5068 ms 12636 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Execution timed out 5049 ms 9632 KB Time limit exceeded
9 Halted 0 ms 0 KB -