Can anyone explain why am I getting TLE for Charges

#include <bits/stdc++.h>
using namespace std;

#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define tc(t) int t;cin >>t;while(t–)
#define ll long long int
#define pb(i) push_back(i)
#define mod 1000000007
#define line “\n”

int main() {
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif
tc(t) {
int n, k;
cin >> n >> k;
string s;
cin >> s;
while (k–) {
int q, dis = 0;
cin >> q;
q–;
if (s[q] == ‘0’) s[q] = ‘1’;
else s[q] = ‘0’;

		// cout << s << line;

		for (int i = 1; i < n; i++) {
			if (s[i - 1] == '0' && s[i] == '0') dis += 2;
			else dis++;
		}
		cout << dis << line;
	}
}
return 0;

}

It’s because your logic does O(k*n) operations, and k, n<=10^5. An optimised way will be to calculate the initial charge and then for each change of charge find the new charge just by looking at its previous and next charges.