Submission #1005042

#TimeUsernameProblemLanguageResultExecution timeMemory
1005042vjudge1Street Lamps (APIO19_street_lamps)C++17
40 / 100
492 ms18928 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int const N=105; int const N1=3e5+5; int const mod=1e9+7; int n,q; string s; int ans[N][N]; set<int> blocked; int check(int a,int b){ if( (blocked.lower_bound(a))==blocked.end() || (*(blocked.lower_bound(a)))>=b) return 1; return 0; } void solve1(){ cin>>s; for(int i=0;i<n;i++) if(s[i]=='0') blocked.insert(i); while(q--){ for(int i=0;i<=n;i++) for(int j=i;j<=n;j++) ans[i][j]+=check(i,j); string o; cin>>o; if(o=="toggle"){ int t; cin>>t; t--; if(s[t]=='1'){ blocked.insert(t); s[t]='0'; } else{ blocked.erase(t); s[t]='1'; } } else{ int a,b; cin>>a>>b; a--;b--; cout<<ans[a][b]<<endl; } } } vector<int> instance[N1]; void solve2(){ cin>>s; for (int i = 0; i < n; ++i) if(s[i]=='1') instance[i].push_back(0); int c=0; while(q--){ c++; string o; cin>>o; if(o=="toggle"){ int t; cin>>t; t--; if(s[t]=='1'){ instance[t].push_back(c); s[t]='0'; } else{ s[t]='1'; instance[t].push_back(c); } } else{ int a,b; cin>>a>>b; a--;b--; instance[a].push_back(c); int sm=0; for(int i=1;i<int(instance[a].size());i+=2) sm+=instance[a][i]-instance[a][i-1]; instance[a].pop_back(); cout<<sm<<endl; } } } int main(){ cin>>n>>q; if(n<=100 && q<=100) solve1(); else{ // retur/n 0; solve2(); } return 0; }
#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...