Submission #985263

#TimeUsernameProblemLanguageResultExecution timeMemory
985263nninStreet Lamps (APIO19_street_lamps)C++14
0 / 100
5022 ms524288 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...