79142024-01-11 22:25:49szasztundeSzínezéscpp17Accepted 50/50483ms19336 KiB
#include <iostream>

using namespace std;

string s;


int main()
{
    int n,q,valt=1,x;
    cin>>n>>q;
    cin>>s;
    s=' '+s;
    for(int i=2;i<=n;i++)
        if(s[i]!=s[i-1]) valt++;
    cout<<valt/2<<endl;
    for(int i=1;i<=q;i++)
    {
        cin>>x;
        if(s[x]=='0') s[x]='1';
        else s[x]='0';
        if(x==1) if(s[x]==s[x+1]) valt--; else valt++;
        else if(x==n) if(s[x]==s[x-1]) valt--; else valt++;
        else if(s[x-1]==s[x+1] and s[x-1]==s[x]) valt=valt-2;
        else if(s[x-1]==s[x+1] and s[x-1]!=s[x]) valt=valt+2;
        cout/*<<s<<" "*/<<valt/2<<endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1808 KiB
2Accepted0/04ms2096 KiB
3Accepted2/23ms2164 KiB
4Accepted2/23ms2304 KiB
5Accepted3/33ms2524 KiB
6Accepted3/33ms2608 KiB
7Accepted3/34ms2748 KiB
8Accepted3/34ms2972 KiB
9Accepted2/24ms3060 KiB
10Accepted2/24ms3068 KiB
11Accepted3/3305ms5300 KiB
12Accepted3/3460ms6924 KiB
13Accepted3/3349ms8448 KiB
14Accepted3/3446ms9716 KiB
15Accepted3/3483ms11320 KiB
16Accepted3/3458ms13088 KiB
17Accepted3/3467ms14520 KiB
18Accepted3/3421ms16232 KiB
19Accepted3/3287ms17912 KiB
20Accepted3/3404ms19336 KiB