Submission #985268

# Submission time Handle Problem Language Result Execution time Memory
985268 2024-05-17T14:05:00 Z nnin Street Lamps (APIO19_street_lamps) C++14
20 / 100
5000 ms 524288 KB
#include<bits/stdc++.h>
using namespace std;

int n, q;
bool status[300005];
vector<pair<int,vector<int>>> mat;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>q;
    string s;
    cin>>s;
    mat.push_back({0, vector<int>(n+1)});
    mat[0].second[0] = 0;
    for(int i=0;i<n;i++) {
        mat[0].second[i+1] = mat[0].second[i];
        if(s[i]-'0'==1) mat[0].second[i+1]++;
        status[i+1] = s[i]-'0';
    }
    for(int i=1;i<=q;i++) {
        cin>>s;
        if(s[0]=='q') {
            int a, b;
            cin>>a>>b;
            int ans = 0;
            for(int j=0;j<mat.size();j++) {
                if(mat[j].second[b-1]-mat[j].second[a-1]!=b-a) continue;
                if(j+1<mat.size()) ans += mat[j+1].first-mat[j].first;
                else ans += i-mat[j].first;
            }
            cout<<ans<<'\n';
        } else {
            int a;
            cin>>a;
            int idx = mat.size();
            mat.push_back({i, mat[idx-1].second});
            for(int j=a;j<=n;j++) mat[idx].second[j] += (status[a] ? -1:1);
            status[a] = !status[a];
        }
    }
}

/*
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 'int main()':
street_lamps.cpp:26:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             for(int j=0;j<mat.size();j++) {
      |                         ~^~~~~~~~~~~
street_lamps.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |                 if(j+1<mat.size()) ans += mat[j+1].first-mat[j].first;
      |                    ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5013 ms 21716 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4188 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Runtime error 299 ms 524288 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 3 ms 2884 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Runtime error 261 ms 524288 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Execution timed out 5013 ms 21716 KB Time limit exceeded
9 Halted 0 ms 0 KB -