7132021-11-18 20:46:59Valaki2Színezéscpp14Accepted 50/5090ms18916 KiB
#include <bits/stdc++.h>
using namespace std;

int n, q;
string s;
vector<int> v;
vector<int> cnt;

void solve() {
    cin >> n >> q >> s;
    v.assign(1 + n + 1, 0);
    for(int i = 1; i <= n; i++) {
        v[i] = s[i - 1] - '0';
    }
    v[0] = -1;
    v[n + 1] = -1;
    cnt.assign(2, 0);
    for(int i = 1; i <= n; i++) {
        if(v[i] != v[i - 1]) {
            cnt[v[i]]++;
        }
    }
    cout << min(cnt[0], cnt[1]) << "\n";
    while(q--) {
        int i;
        cin >> i;
        if(n == 1) {
            cout << "0\n";
            continue;
        }
        if(i == 1 || i == n) {
            int j = 0;
            if(i == 1) {
                j = 2;
            }
            if(i == n) {
                j = n - 1;
            }
            if(v[i] != v[j]) {
                cnt[v[i]]--;
            } else {
                cnt[1 - v[i]]++;
            }
            v[i] = 1 - v[i];
        } else {
            v[i] = 1 - v[i];
            if(v[i - 1] == v[i] && v[i + 1] == v[i]) {
                cnt[0]--;
                cnt[1]--;
            }
            if(v[i - 1] != v[i] && v[i + 1] == v[i]) {
                //
            }
            if(v[i - 1] == v[i] && v[i + 1] != v[i]) {
                //
            }
            if(v[i - 1] != v[i] && v[i + 1] != v[i]) {
                cnt[0]++;
                cnt[1]++;
            }
        }
        cout << min(cnt[0], cnt[1]) << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1944 KiB
2Accepted0/02ms2184 KiB
3Accepted2/21ms2084 KiB
4Accepted2/21ms2096 KiB
5Accepted3/31ms2092 KiB
6Accepted3/38ms2100 KiB
7Accepted3/31ms2124 KiB
8Accepted3/31ms2132 KiB
9Accepted2/21ms2140 KiB
10Accepted2/21ms2144 KiB
11Accepted3/356ms5756 KiB
12Accepted3/352ms7236 KiB
13Accepted3/390ms8692 KiB
14Accepted3/354ms10160 KiB
15Accepted3/357ms11612 KiB
16Accepted3/354ms13076 KiB
17Accepted3/354ms14520 KiB
18Accepted3/357ms16000 KiB
19Accepted3/356ms17448 KiB
20Accepted3/352ms18916 KiB