#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
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;
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
33 ms |
53084 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18792 KB |
Output is correct |
2 |
Correct |
4 ms |
18792 KB |
Output is correct |
3 |
Correct |
5 ms |
18792 KB |
Output is correct |
4 |
Correct |
6 ms |
18796 KB |
Output is correct |
5 |
Runtime error |
411 ms |
65112 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
18792 KB |
Output is correct |
2 |
Correct |
5 ms |
18792 KB |
Output is correct |
3 |
Correct |
5 ms |
18644 KB |
Output is correct |
4 |
Correct |
4 ms |
18792 KB |
Output is correct |
5 |
Runtime error |
406 ms |
64656 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Runtime error |
33 ms |
53084 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |