This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using std::cin, std::cout, std::vector, std::set, std::endl, std::string, std::map,std::pair,std::queue;
#ifdef LOCAL
#define file freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#else
#define file ;;
#endif
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using Tree = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include <random>
int main(){
file;
int n,q;
cin >> n >> q;
string s;
cin >> s;
vector<vector<int>> hist(n+1,vector<int>(1,0));
for(int i=1;i<=q;i++){
string ty;
cin >> ty;
if(ty[0]=='q'){
int a,b;
cin >> a >> b;
--a;
--b;
int ans = (((s[a]=='1' && hist[a].size()%2==1) || (s[a]=='0' && hist[a].size()%2==0)) ? i-hist[a].back():0);
for(int i=(s[a]=='0')+1;i<hist[a].size();i+=2){
ans+=hist[a][i]-hist[a][i-1];
}
cout << ans << endl;
}
else if(ty[0]=='t'){
int a;
cin >> a;
hist[a-1].push_back(i);
}
}
return 0;
}
Compilation message (stderr)
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:34:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i=(s[a]=='0')+1;i<hist[a].size();i+=2){
| ~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |