18312022-12-04 16:02:23kdbSzínezéscpp11Wrong answer 10/50430ms6552 KiB
#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define ll long long

ostream& operator<<(ostream& os, vector<int>& input)
{
    for (auto i : input)
    {
        os << i << " ";
    }
    return os;
}

int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<int>vec, d(2);
    string s; cin >> s;
    vec.push_back(0); 
    for (int i = 0; i < s.size(); i++) vec.push_back(s[i] - '0');

    for (size_t i = 1; i < n + 1; i++)
    {
        if (vec[i] != vec[i - 1]) d[vec[i]]++;
    }
    if (!vec[1]) d[vec[0]]++;
    cout << min(d[0], d[1]) << endl;

    while (q--) 
    {
        int a;
        cin >> a;
        if (a == 1 && vec[1] != vec[2])
        {
            d[vec[a]]--;
        }
        else if (a == 1 && vec[1] == vec[2])
        {
            d[1-vec[a]]++;
        }
        else if (a == n && vec[n] != vec[n-1])
        {
            d[vec[a]]++;
        }
        else if (a == n && vec[n] == vec[n-1])
        {
            d[1-vec[a]]--;
        }
        else if (vec[a - 1] == vec[a] && vec[a] == vec[a + 1])
        {
            d[0]++;
            d[1]++;
        }
        else if (vec[a - 1] == vec[a + 1] && vec[a] != vec[a + 1])
        {
            d[0]--;
            d[1]--;
        }
        vec[a] = 1 - vec[a];
        cout << min(d[0], d[1]) << endl;
    }
    return 0;
}
/*
5 3
01001
2
1
5

*/
SubtaskSumTestVerdictTimeMemory
base10/50
1Accepted0/03ms1860 KiB
2Accepted0/04ms2144 KiB
3Accepted2/22ms2392 KiB
4Wrong answer0/22ms2488 KiB
5Wrong answer0/32ms2640 KiB
6Wrong answer0/32ms2780 KiB
7Accepted3/34ms3132 KiB
8Wrong answer0/33ms3188 KiB
9Accepted2/24ms3148 KiB
10Wrong answer0/24ms3280 KiB
11Wrong answer0/3233ms5964 KiB
12Wrong answer0/3228ms6168 KiB
13Wrong answer0/3411ms6120 KiB
14Accepted3/3237ms6120 KiB
15Wrong answer0/3284ms6248 KiB
16Wrong answer0/3430ms6264 KiB
17Wrong answer0/3305ms6140 KiB
18Wrong answer0/3421ms6140 KiB
19Wrong answer0/3243ms6144 KiB
20Wrong answer0/3298ms6552 KiB