#include <bits/stdc++.h>
#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
const int INF = INT_MAX;
const int NINF = INT_MIN;
typedef long long int ll;
using namespace std;
void solve(){
int n,k;
cin>>n>>k;
string s;cin>>s;
ll tot = 0;
for (int i = 0; i < n-1; ++i) {
if(s[i]==s[i+1]) tot+=2;
else tot+=1;
}
for (int i = 0; i < k; ++i) {
int num;cin>>num;
if(n==1){cout<<"0"<<endl;continue;}
if(num==1){
if(s[0]==s[1]) tot-=1;
else tot++;
if(s[0]=='1') s[0] = '0';
else s[0] = '1';
}
else if(num==n){
if(s[n-1]==s[n-2]) tot-=1;
else tot++;
if(s[n-1]=='1') s[n-1] = '0';
else s[n-1] = '1';
}
else{
if(s[num-2] != s[num]){
if(s[num-1]=='1') s[num-1] = '0';
else s[num-1] = '1';
continue;
}
if((s[num-2] == s[num]) && (s[num-1] == s[num])) tot-=2;
else tot+=2;
if(s[num-1]=='1') s[num-1] = '0';
else s[num-1] = '1';
}
cout<<tot<<endl;
}
}
int main()
{
int t;
cin>>t;
while (t--) solve();
}
Can someone help me with this? I can’t identify the problem
[updated] CodeChef: Practical coding for everyone
CodeChef: Practical coding for everyone
