15912022-11-28 18:46:05kicsiboglarSzínezéscpp11Accepted 50/50483ms5928 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

string s;
long long n,i,m,j,a,poz,db0,db1;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>s;
    vector <int> x(n+2,0);
    for (i=0;i<n;++i)
    {
        if (s[i]=='1') x[i+1]=1;
    }
     x[n+1]=x[n] xor 1;
    int db=0;
    if (x[1]==0) db0++;
    else db1++;
    for (i=2;i<=n+1;++i)
    {
        if (x[i]==x[i-1]) db++;
        else db=0;

        if (db==0)
        {
         if (i!=n+1)
         {
             if (x[i]==0) db0++;
             else db1++;
         }
        }
    }
    if (db0<db1) cout<<db0<<"\n";
    else cout<<db1<<"\n";

    for (i=1;i<=m;++i)
    {
        cin>>a;
        if (a==1)///eleje
        {
            if (x[2]!=x[1])
            {
                if (x[1]==0) db0--;
                else db1--;
            }
            else
            {
                if (x[1]==0) db1++;
                else db0++;
            }
        }
        else if (a==n)
        {
            if (x[n]!=x[n-1])
            {
               if (x[n]==0) db0--;
                else db1--;
            }
            else
            {
                if (x[n]==0) db1++;
                else db0++;
            }
        }
        else
        {
            if (x[a]==x[a-1])
            {
                if (x[a]==x[a+1])
                {
                    db0++;
                    db1++;
                }
            }
            else
            {
                if (x[a]!=x[a+1])
                {
                    db0--;
                    db1--;
                }
            }
        }
        x[a]=x[a] xor 1;
        if (db0<db1) cout<<db0<<"\n";
        else cout<<db1<<"\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1824 KiB
2Accepted0/03ms2248 KiB
3Accepted2/22ms2124 KiB
4Accepted2/22ms2328 KiB
5Accepted3/32ms2528 KiB
6Accepted3/32ms2628 KiB
7Accepted3/34ms2840 KiB
8Accepted3/33ms3060 KiB
9Accepted2/23ms3040 KiB
10Accepted2/23ms3036 KiB
11Accepted3/3379ms5076 KiB
12Accepted3/3437ms5080 KiB
13Accepted3/3430ms5308 KiB
14Accepted3/3351ms5520 KiB
15Accepted3/3407ms5716 KiB
16Accepted3/3483ms5668 KiB
17Accepted3/3303ms5684 KiB
18Accepted3/3284ms5668 KiB
19Accepted3/3382ms5668 KiB
20Accepted3/3374ms5928 KiB