226232026-01-15 12:38:32AKrisztianSzínezéscpp17Wrong answer 0/50414ms1860 KiB
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int N, Q;
    cin >> N >> Q;
    string sor;
    cin >> sor;
    int K, p=0, k=0;
    bool pp=0, kk=0;

    for (int j=0; j<N; j++)
    {
        if (sor[j]=='1' and kk==0)
        {
            kk=1;
            pp=0;
            k=k+1;
        }
        if (sor[j]=='0' and pp==0)
        {
            kk=0;
            pp=1;
            p=p+1;
        }
    }
    cout << min(k, p);

    for (int i=0; i<Q; i++)
    {
        cin >> K;
        if (K<N and K>1)
        {
            if (sor[K-1]==sor[K-2] and sor[K-1]==sor[K])
            {
                p=p+1;
                k=k+1;
            }
            if ((sor[K-1]!=sor[K-2]) and (sor[K-1]!=sor[K]))
            {
                p=p-1;
                k=k-1;
            }
        }
        else if (K==N)
        {
            if (sor[K-1]==sor[K-2])
            {
                if (sor[K-1]=='1')
                {
                    p=p+1;
                }
                else
                {
                    k=k+1;
                }
            }
            if (sor[K-1]!=sor[K-2])
            {
                if (sor[K-1]=='1')
                {
                    k=k-1;
                }
                else
                {
                    p=p-1;
                }
            }
        }
        else if (K==1)
        {
            if (sor[K-1]==sor[K])
            {
                if (sor[K-1]=='1')
                {
                    p=p+1;
                }
                else
                {
                    k=k+1;
                }
            }
            if (sor[K-1]!=sor[K])
            {
                if (sor[K]=='1')
                {
                    k=k-1;
                }
                else
                {
                    p=p-1;
                }
            }
        }
        if (sor[K-1]=='1')
        {
            sor[K-1]='0';
        }
        else
        {
            sor[K-1]='1';
        }
        cout << min(k, p) << endl;
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms316 KiB
2Wrong answer0/03ms316 KiB
3Wrong answer0/21ms500 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/33ms316 KiB
8Wrong answer0/33ms316 KiB
9Wrong answer0/22ms316 KiB
10Wrong answer0/23ms316 KiB
11Wrong answer0/3414ms1852 KiB
12Wrong answer0/3398ms1808 KiB
13Wrong answer0/3398ms1840 KiB
14Wrong answer0/3412ms1732 KiB
15Wrong answer0/3386ms1732 KiB
16Wrong answer0/3384ms1776 KiB
17Wrong answer0/3414ms1860 KiB
18Wrong answer0/3384ms1772 KiB
19Wrong answer0/3388ms1732 KiB
20Wrong answer0/3402ms1804 KiB