17852022-12-03 15:15:571478Színezéscpp11Accepted 50/5046ms4792 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

int main()
{
    //ifstream cin("be.txt");

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;

    int q;
    cin >> q;

    string s;
    cin >> s;

    int i = 0;
    vector<int> c(2);
    while (i < n)
    {
        if (s[i] != s[i - 1] || i == 0)
        {
            c[s[i] - '0']++;
        }
        i++;
    }
    cout << min(c[0], c[1]) << ln;

    while (q--)
    {
        int change;
        cin >> change;
        change--;
        s[change] = abs(s[change] - '1') + '0';

        if (change == 0)
        {
            if (s[change] != s[change + 1])
                c[s[change] - '0']++;
            else
                c[abs(s[change] - '1')]--;
        }
        else if (change == n - 1)
        {
            if (s[change] != s[change - 1])
                c[s[change] - '0']++;
            else
                c[abs(s[change] - '1')]--;
        }
        else if (s[change] != s[change - 1] && s[change] != s[change + 1])
        {
            c[0]++;
            c[1]++;
        }
        else if (s[change] == s[change - 1] && s[change] == s[change + 1])
        {
            c[0]--;
            c[1]--;
        }

        cout << min(c[0], c[1]) << ln;
    }


    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/03ms2216 KiB
3Accepted2/22ms2260 KiB
4Accepted2/22ms2428 KiB
5Accepted3/32ms2500 KiB
6Accepted3/32ms2640 KiB
7Accepted3/32ms2728 KiB
8Accepted3/32ms2860 KiB
9Accepted2/22ms2932 KiB
10Accepted2/22ms3072 KiB
11Accepted3/346ms3784 KiB
12Accepted3/346ms3972 KiB
13Accepted3/346ms4364 KiB
14Accepted3/346ms4316 KiB
15Accepted3/346ms4524 KiB
16Accepted3/346ms4556 KiB
17Accepted3/346ms4556 KiB
18Accepted3/345ms4728 KiB
19Accepted3/343ms4748 KiB
20Accepted3/345ms4792 KiB