18322022-12-04 16:05:32kdbSzínezéscpp11Wrong answer 10/50503ms6820 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]]++;
    }
    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/03ms1824 KiB
2Accepted0/04ms2316 KiB
3Accepted2/22ms2284 KiB
4Wrong answer0/22ms2488 KiB
5Wrong answer0/32ms2688 KiB
6Wrong answer0/32ms2892 KiB
7Accepted3/34ms3208 KiB
8Wrong answer0/34ms3176 KiB
9Accepted2/24ms3164 KiB
10Wrong answer0/23ms3136 KiB
11Wrong answer0/3397ms5756 KiB
12Wrong answer0/3503ms5952 KiB
13Wrong answer0/3238ms6160 KiB
14Accepted3/3239ms6412 KiB
15Wrong answer0/3231ms6308 KiB
16Wrong answer0/3246ms6576 KiB
17Wrong answer0/3244ms6820 KiB
18Wrong answer0/3312ms6768 KiB
19Wrong answer0/3356ms6720 KiB
20Wrong answer0/3238ms6728 KiB