79942024-01-12 09:50:08BenedekMartonSzínezéscpp17Accepted 50/50517ms4772 KiB
#include <iostream>

using namespace std;

int main()
{
    int n, q, szk=1, v;
    cin >> n >> q;
    char c;
    bool g[n];
    cin.get();
    cin.get(c);
    g[0]=c-'0';
    for(int i=1; i<n; i++)
    {
        cin.get(c);
        g[i]=c-'0';
        if(g[i-1]!=g[i])
        {
            szk++;
        }
    }
    cout << szk/2 << endl;
    for(int i=0; i<q; i++)
    {
        cin >> v; v--;
        if(v==0)
        {
            if(g[1]!=g[0])
            {
                szk--;
                //cout << "k";
            }
            else
            {
                szk++;
                //cout << "h";
            }
        }
        else if(v==n-1)
        {
            if(g[n-1]!=g[n-2])
            {
                szk--;
                //cout << "c";
            }
            else
            {
                szk++;
                //cout << "a";
            }
        }
        else if(g[v-1]==g[v+1])
        {
            if(g[v]==g[v-1])
            {
                szk=szk+2;
                //cout << "b";
            }
            else
            {
                szk=szk-2;
                //cout << "p";
            }
        }
        cout << szk/2 << endl;
        g[v]=!g[v];
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2052 KiB
2Accepted0/06ms2368 KiB
3Accepted2/23ms2332 KiB
4Accepted2/23ms2544 KiB
5Accepted3/33ms2756 KiB
6Accepted3/33ms2968 KiB
7Accepted3/34ms3356 KiB
8Accepted3/34ms3328 KiB
9Accepted2/24ms3412 KiB
10Accepted2/24ms3624 KiB
11Accepted3/3291ms4032 KiB
12Accepted3/3310ms4144 KiB
13Accepted3/3296ms4320 KiB
14Accepted3/3451ms4644 KiB
15Accepted3/3477ms4576 KiB
16Accepted3/3287ms4772 KiB
17Accepted3/3517ms4596 KiB
18Accepted3/3442ms4720 KiB
19Accepted3/3499ms4612 KiB
20Accepted3/3510ms4496 KiB