#pragma GCC optimize("Ofast,unroll-loops,inline")
#pragma GCC target("avx2,bmi,bmi2")
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define pb push_back
#define prec fixed<<setprecision
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define open(name) if(fopen(name".inp", "r")){freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
using namespace std;
const int maxN=3e5+69;
const int mod=998244353;
ll n,q;
string s;
vector<ll> BIT[maxN];
vector<ll> node[maxN];
void fakeUpdate(int x, int y) {
for (; x <= n+1; x += x & -x)
node[x].push_back(y);
}
void fakeGet(int x, int y) {
for (; x ; x -= x & -x)
node[x].push_back(y);
}
void update(int x, int yy, int val) {
for (; x <= n+1; x += x & -x)
for (int y = lower_bound(all(node[x]), yy) - node[x].begin() + 1; y <= node[x].size(); y += y & -y)
BIT[x][y-1] += val;
}
int get(int x, int yy) {
int res = 0;
for (; x>0 ; x -= x & -x)
for (int y = lower_bound(all(node[x]), yy) - node[x].begin() + 1; y > 0; y -= y & -y)
res += BIT[x][y-1];
return res;
}
vector<pll> query;
set<ll> off;
ll ffirst(ll x){return (off.lower_bound(x)==off.begin()?0:*(--off.lower_bound(x)));}
ll flast(ll x){return (off.upper_bound(x)==off.end()?n+1:(*off.upper_bound(x)));}
void Enter(){
cin>>n>>q>>s;s=' '+s;string x=s;
for(int i=1;i<=n;i++)if(s[i]=='0')off.insert(i);
for(int i=1;i<=q;i++){
string type;
ll u,v;
cin>>type>>u;
if(type[0]=='t'){
query.pb({u,0});
ll ax=ffirst(u),ay=u,bx=u,by=flast(u);
fakeUpdate(ax+1,ay+1);fakeUpdate(ax+1,by+1);fakeUpdate(bx+1,ay+1);fakeUpdate(bx+1,by+1);
if(s[u]=='0')off.erase(u);
else off.insert(u);
s[u]='1'+'0'-s[u];
} else cin>>v,query.pb({u,v}),fakeGet(u,v);
}
off.clear();s=x;
for(int i=1;i<=n+1;i++)sort(all(node[i])),node[i].resize(unique(all(node[i]))-node[i].begin()),BIT[i].resize(node[i].size());
for(int i=1;i<=n;i++)if(s[i]=='0')off.insert(i);
for(int i=1;i<=q;i++){
auto [u,v]=query[i-1];
if(!v){
ll ax=ffirst(u),ay=u,bx=u,by=flast(u);
if(s[u]=='0')i=-i;
update(ax+1,ay+1,i);update(ax+1,by+1,-i);update(bx+1,ay+1,-i);update(bx+1,by+1,i);
if(s[u]=='0')i=-i;
if(s[u]=='0')off.erase(u);
else off.insert(u);
s[u]='1'+'0'-s[u];
} else cout<<get(u,v)+i*(v<=flast(u)&&ffirst(v)<u)<<endl;
}
}
//amogus
signed main(){
//open("PAINT");
cin.tie(nullptr);ios_base::sync_with_stdio(NULL);
//ll t=1;cin>>t;while(t--)
Enter();
}
Compilation message
street_lamps.cpp: In function 'void update(int, int, int)':
street_lamps.cpp:29:77: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int y = lower_bound(all(node[x]), yy) - node[x].begin() + 1; y <= node[x].size(); y += y & -y)
| ~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14428 KB |
Output is correct |
2 |
Correct |
4 ms |
14428 KB |
Output is correct |
3 |
Correct |
5 ms |
14684 KB |
Output is correct |
4 |
Correct |
5 ms |
14428 KB |
Output is correct |
5 |
Correct |
5 ms |
14428 KB |
Output is correct |
6 |
Correct |
4 ms |
14568 KB |
Output is correct |
7 |
Correct |
4 ms |
14428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
328 ms |
33836 KB |
Output is correct |
2 |
Correct |
442 ms |
41764 KB |
Output is correct |
3 |
Correct |
739 ms |
50864 KB |
Output is correct |
4 |
Correct |
1864 ms |
92696 KB |
Output is correct |
5 |
Correct |
1561 ms |
84728 KB |
Output is correct |
6 |
Correct |
1895 ms |
93668 KB |
Output is correct |
7 |
Correct |
1084 ms |
69812 KB |
Output is correct |
8 |
Correct |
654 ms |
56604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14680 KB |
Output is correct |
2 |
Correct |
7 ms |
14684 KB |
Output is correct |
3 |
Correct |
6 ms |
14560 KB |
Output is correct |
4 |
Correct |
5 ms |
14556 KB |
Output is correct |
5 |
Correct |
2943 ms |
115024 KB |
Output is correct |
6 |
Correct |
2410 ms |
99660 KB |
Output is correct |
7 |
Correct |
1693 ms |
82432 KB |
Output is correct |
8 |
Correct |
770 ms |
57848 KB |
Output is correct |
9 |
Correct |
123 ms |
23768 KB |
Output is correct |
10 |
Correct |
129 ms |
26864 KB |
Output is correct |
11 |
Correct |
128 ms |
26612 KB |
Output is correct |
12 |
Correct |
1151 ms |
70024 KB |
Output is correct |
13 |
Correct |
751 ms |
57128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14428 KB |
Output is correct |
2 |
Correct |
7 ms |
14684 KB |
Output is correct |
3 |
Correct |
8 ms |
14740 KB |
Output is correct |
4 |
Correct |
9 ms |
14684 KB |
Output is correct |
5 |
Correct |
1032 ms |
63992 KB |
Output is correct |
6 |
Correct |
1441 ms |
79228 KB |
Output is correct |
7 |
Correct |
1954 ms |
94904 KB |
Output is correct |
8 |
Correct |
2773 ms |
105056 KB |
Output is correct |
9 |
Correct |
582 ms |
47404 KB |
Output is correct |
10 |
Correct |
510 ms |
42216 KB |
Output is correct |
11 |
Correct |
565 ms |
47000 KB |
Output is correct |
12 |
Correct |
482 ms |
42124 KB |
Output is correct |
13 |
Correct |
563 ms |
48008 KB |
Output is correct |
14 |
Correct |
482 ms |
42404 KB |
Output is correct |
15 |
Correct |
1014 ms |
71476 KB |
Output is correct |
16 |
Correct |
659 ms |
56496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14428 KB |
Output is correct |
2 |
Correct |
4 ms |
14428 KB |
Output is correct |
3 |
Correct |
5 ms |
14684 KB |
Output is correct |
4 |
Correct |
5 ms |
14428 KB |
Output is correct |
5 |
Correct |
5 ms |
14428 KB |
Output is correct |
6 |
Correct |
4 ms |
14568 KB |
Output is correct |
7 |
Correct |
4 ms |
14428 KB |
Output is correct |
8 |
Correct |
328 ms |
33836 KB |
Output is correct |
9 |
Correct |
442 ms |
41764 KB |
Output is correct |
10 |
Correct |
739 ms |
50864 KB |
Output is correct |
11 |
Correct |
1864 ms |
92696 KB |
Output is correct |
12 |
Correct |
1561 ms |
84728 KB |
Output is correct |
13 |
Correct |
1895 ms |
93668 KB |
Output is correct |
14 |
Correct |
1084 ms |
69812 KB |
Output is correct |
15 |
Correct |
654 ms |
56604 KB |
Output is correct |
16 |
Correct |
7 ms |
14680 KB |
Output is correct |
17 |
Correct |
7 ms |
14684 KB |
Output is correct |
18 |
Correct |
6 ms |
14560 KB |
Output is correct |
19 |
Correct |
5 ms |
14556 KB |
Output is correct |
20 |
Correct |
2943 ms |
115024 KB |
Output is correct |
21 |
Correct |
2410 ms |
99660 KB |
Output is correct |
22 |
Correct |
1693 ms |
82432 KB |
Output is correct |
23 |
Correct |
770 ms |
57848 KB |
Output is correct |
24 |
Correct |
123 ms |
23768 KB |
Output is correct |
25 |
Correct |
129 ms |
26864 KB |
Output is correct |
26 |
Correct |
128 ms |
26612 KB |
Output is correct |
27 |
Correct |
1151 ms |
70024 KB |
Output is correct |
28 |
Correct |
751 ms |
57128 KB |
Output is correct |
29 |
Correct |
5 ms |
14428 KB |
Output is correct |
30 |
Correct |
7 ms |
14684 KB |
Output is correct |
31 |
Correct |
8 ms |
14740 KB |
Output is correct |
32 |
Correct |
9 ms |
14684 KB |
Output is correct |
33 |
Correct |
1032 ms |
63992 KB |
Output is correct |
34 |
Correct |
1441 ms |
79228 KB |
Output is correct |
35 |
Correct |
1954 ms |
94904 KB |
Output is correct |
36 |
Correct |
2773 ms |
105056 KB |
Output is correct |
37 |
Correct |
582 ms |
47404 KB |
Output is correct |
38 |
Correct |
510 ms |
42216 KB |
Output is correct |
39 |
Correct |
565 ms |
47000 KB |
Output is correct |
40 |
Correct |
482 ms |
42124 KB |
Output is correct |
41 |
Correct |
563 ms |
48008 KB |
Output is correct |
42 |
Correct |
482 ms |
42404 KB |
Output is correct |
43 |
Correct |
1014 ms |
71476 KB |
Output is correct |
44 |
Correct |
659 ms |
56496 KB |
Output is correct |
45 |
Correct |
131 ms |
23988 KB |
Output is correct |
46 |
Correct |
225 ms |
28444 KB |
Output is correct |
47 |
Correct |
882 ms |
53232 KB |
Output is correct |
48 |
Correct |
1837 ms |
92476 KB |
Output is correct |
49 |
Correct |
143 ms |
26356 KB |
Output is correct |
50 |
Correct |
133 ms |
26048 KB |
Output is correct |
51 |
Correct |
146 ms |
27428 KB |
Output is correct |
52 |
Correct |
177 ms |
29432 KB |
Output is correct |
53 |
Correct |
182 ms |
29308 KB |
Output is correct |
54 |
Correct |
180 ms |
29368 KB |
Output is correct |