18802022-12-06 22:05:13TomaSajtSzínezéscpp17Accepted 50/5048ms5444 KiB
#include <bits/stdc++.h>
#define speed ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main() {
    speed;
    int n, q;
    cin >> n >> q;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        char c; cin >> c;
        v[i] = c == '1' ? 1 : 0;
    }
    int cnts[2] = { 0,0 };
    cnts[v[0]]++;
    for (int i = 1; i < n; i++) {
        if (v[i - 1] != v[i]) cnts[v[i]]++;
    }
    cout << (cnts[0] + cnts[1]) / 2 << '\n';
    while (q--) {
        int k; cin >> k; k--;
        if (k == 0) {
            if (v[0] == v[1]) cnts[1 - v[0]]++;
            else cnts[v[0]]--;
        }
        else if (k == n - 1) {
            if (v[n - 1] == v[n - 2]) cnts[1 - v[n - 1]]++;
            else cnts[v[n - 1]]--;
        }
        else if (v[k - 1] == v[k + 1]) {
            if (v[k] == v[k - 1]) cnts[0]++, cnts[1]++;
            else cnts[0]--, cnts[1]--;
        }
        v[k] = 1 - v[k];
        cout << (cnts[0] + cnts[1]) / 2 << '\n';
    }
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/03ms2232 KiB
3Accepted2/22ms2256 KiB
4Accepted2/22ms2428 KiB
5Accepted3/32ms2652 KiB
6Accepted3/32ms2884 KiB
7Accepted3/32ms3000 KiB
8Accepted3/32ms2976 KiB
9Accepted2/22ms3168 KiB
10Accepted2/22ms3280 KiB
11Accepted3/348ms4752 KiB
12Accepted3/348ms4956 KiB
13Accepted3/348ms4956 KiB
14Accepted3/348ms4956 KiB
15Accepted3/348ms5136 KiB
16Accepted3/348ms5140 KiB
17Accepted3/348ms5140 KiB
18Accepted3/346ms5232 KiB
19Accepted3/348ms5360 KiB
20Accepted3/346ms5444 KiB