-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharges.cpp
38 lines (29 loc) · 794 Bytes
/
charges.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
using namespace std;
#define long long long int
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T; cin >> T;
while (T--) {
int N, K;
cin >> N >> K;
int dist = 0;
string S; cin >> S;
for (int i = 1; i < N; i++)
dist += S[i] != S[i - 1] ? 1 : 2;
while (K--) {
int Q; cin >> Q;
if (--Q > 0) {
dist -= S[Q] != S[Q - 1] ? 1 : 2;
dist += S[Q] != S[Q - 1] ? 2 : 1;
}
if (Q + 1 < N) {
dist -= S[Q] != S[Q + 1] ? 1 : 2;
dist += S[Q] != S[Q + 1] ? 2 : 1;
}
S[Q] = S[Q] == '0' ? '1' : '0';
cout << dist << "\n";
}
}
}