Submission #985263

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

int n, q;
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]++;
    }
    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]++;
        }
    }
}

/*
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:24: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]
   24 |             for(int j=0;j<mat.size();j++) {
      |                         ~^~~~~~~~~~~
street_lamps.cpp:26: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]
   26 |                 if(j+1<mat.size()) ans += mat[j+1].first-mat[j].first;
      |                    ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5022 ms 21972 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Runtime error 391 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 Incorrect 2 ms 1628 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -