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>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
using namespace std;
const int mxn=2e3+5;
int a[mxn][mxn]{0},b[mxn][mxn]{0},ans[mxn]{0},n;
vector<pii>qr[mxn];
multiset<int>ms,ms2;
vector<ll>bit[mxn];
vector<int>bval[mxn];
vector<int>val[mxn];
void build(){
for(int i=1;i<=n;i++){
if(val[i].empty())continue;
sort(val[i].begin(),val[i].end());
for(auto it : val[i]){
for(int j=i;j<=n;j+=j&-j){
if(bval[j].empty()||bval[j].back()!=it)bval[j].pb(it);
}
}
}
for(int i=1;i<=n;i++)bit[i].resize((int)bval[i].size()+1,0);
}
int ub(int x,int y){
return upper_bound(bval[x].begin(),bval[x].end(),y)-bval[x].begin();
}
void upd(int i,int j,int amt){
for(int x=i;x<=n;x+=x&-x)for(int y=ub(x,j);y<bit[x].size();y+=y&-y)bit[x][y]+=amt;
}
int query(int a,int b,int res=0){
for(int x=a;x>0;x-=x&-x)for(int y=ub(x,b);y>0;y-=y&-y)res+=bit[x][y];
return res;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int q;cin>>n>>q;
for(int i=1;i<=n;i++){
char x;cin>>x;a[0][i]=x-'0',b[0][i]=b[0][i-1]+a[0][i];
}
for(int i=1;i<=q;i++){
string s;cin>>s;ans[i]=-1;
if(s=="toggle"){int x;cin>>x;
for(int j=1;j<=n;j++){
if(j==x)a[i][j]=!a[i-1][j];
else a[i][j]=a[i-1][j];
b[i][j]=b[i][j-1]+a[i][j];
}
}
else {
for(int j=1;j<=n;j++)a[i][j]=a[i-1][j],b[i][j]=b[i][j-1]+a[i][j];
int l,r;cin>>l>>r;int ans=0;
for(int j=0;j<=i-1;j++)if(b[j][r-1]-b[j][l-1]==r-l)ans++;
cout<<ans<<'\n';
}
}
}
Compilation message (stderr)
street_lamps.cpp: In function 'void upd(int, int, int)':
street_lamps.cpp:38:49: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int x=i;x<=n;x+=x&-x)for(int y=ub(x,j);y<bit[x].size();y+=y&-y)bit[x][y]+=amt;
| ~^~~~~~~~~~~~~~
# | 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... |