Submission #594930

#TimeUsernameProblemLanguageResultExecution timeMemory
594930penguinhackerStreet Lamps (APIO19_street_lamps)C++17
20 / 100
5034 ms33508 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=3e5; int n, q, ans[mxN], st[mxN]; string s; vector<int> changes[mxN]; vector<ar<int, 2>> qry[mxN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> q >> s; for (int i=0; i<n; ++i) if (s[i]=='0') changes[i].push_back(-1); for (int i=0; i<q; ++i) { string type; cin >> type; if (type=="toggle") { int x; cin >> x, --x; changes[x].push_back(i); } else { int l, r; cin >> l >> r, --l, r-=2; qry[r].push_back({l, i}); } ans[i]=-1; } for (int i=0; i<n; ++i) { for (int j=0; j<changes[i].size(); j+=2) { int b=j+1<changes[i].size()?changes[i][j+1]:q-1; for (int k=changes[i][j]+1; k<=b; ++k) st[k]=i+1; } for (auto [l, t] : qry[i]) { ans[t]=0; for (int j=0; j<=t; ++j) ans[t]+=st[j]<=l; } } for (int i=0; i<q; ++i) if (~ans[i]) cout << ans[i] << "\n"; return 0; }

Compilation message (stderr)

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for (int j=0; j<changes[i].size(); j+=2) {
      |                 ~^~~~~~~~~~~~~~~~~~
street_lamps.cpp:36:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |    int b=j+1<changes[i].size()?changes[i][j+1]:q-1;
      |          ~~~^~~~~~~~~~~~~~~~~~
#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...