18302022-12-04 15:50:23kdbSzínezéscpp11Wrong answer 10/50448ms6996 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(s[0]-'0'); vec.push_back(s[0]-'0');
    for (int i = 1; i < s.size(); i++) vec.push_back(s[i] - '0');
    vec.push_back(1 - vec[n]);
    for (size_t i = 1; i < n + 1; i++) if (vec[i] != vec[i + 1]) d[vec[i]]++;
    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/03ms1832 KiB
2Accepted0/04ms2268 KiB
3Accepted2/22ms2252 KiB
4Wrong answer0/22ms2456 KiB
5Wrong answer0/32ms2552 KiB
6Wrong answer0/32ms2756 KiB
7Accepted3/33ms2992 KiB
8Wrong answer0/34ms3220 KiB
9Accepted2/23ms3276 KiB
10Wrong answer0/23ms3468 KiB
11Wrong answer0/3233ms6156 KiB
12Wrong answer0/3234ms6060 KiB
13Wrong answer0/3263ms6288 KiB
14Accepted3/3314ms6232 KiB
15Wrong answer0/3448ms6308 KiB
16Wrong answer0/3444ms6456 KiB
17Wrong answer0/3340ms6396 KiB
18Wrong answer0/3230ms6776 KiB
19Wrong answer0/3432ms6996 KiB
20Wrong answer0/3240ms6852 KiB