18342022-12-04 17:35:34kdbSzínezéscpp11Wrong answer 10/50481ms5872 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(n+1), d(2);
    string s; cin >> s;
    for (size_t i = 1; i < n+1; i++)
    {
        vec[i] = s[i - 1] - '0';
        if (vec[i] == 1 && vec[i - 1] == 0) d[1]++;
        else if (vec[i] == 0 && vec[i - 1] == 1) d[0]++;
    }
    if (vec[1] == 0) d[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/03ms1828 KiB
2Accepted0/04ms2140 KiB
3Accepted2/22ms2144 KiB
4Wrong answer0/22ms2228 KiB
5Wrong answer0/32ms2228 KiB
6Wrong answer0/32ms2356 KiB
7Accepted3/33ms2564 KiB
8Wrong answer0/34ms2632 KiB
9Accepted2/23ms2704 KiB
10Wrong answer0/23ms2708 KiB
11Wrong answer0/3405ms5220 KiB
12Wrong answer0/3481ms5160 KiB
13Wrong answer0/3236ms5296 KiB
14Accepted3/3236ms5364 KiB
15Wrong answer0/3233ms5372 KiB
16Wrong answer0/3280ms5364 KiB
17Wrong answer0/3342ms5632 KiB
18Wrong answer0/3477ms5828 KiB
19Wrong answer0/3234ms5872 KiB
20Wrong answer0/3451ms5848 KiB