31362023-02-19 13:08:26horvathabelSzínezéscpp17Wrong answer 10/50504ms4956 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,q; 
	cin>>n>>q;
	string s; 
	cin>>s;
	pair<int, int> ans={0,0}; 
	for (int i=0; i<n;i++){
		if (s[i]=='0'){
			ans.first++;
			int j=i;  
			while (s[j]=='0') j++;
			i=j-1;
		}
		else{
			ans.second++;
			int j=i;
			while (s[j]=='1') j++;
			i=j-1;
		}
	}
	cout<<min(ans.first,ans.second)<<endl;
	for (int i=0; i<q;i++){
		int z;
		cin>>z; 
		z--;
		if (s[z]=='0'){
			s[z]='1';
			if (z==0){
				if (s[1]=='1'){
					ans.first--;
					cout<<min(ans.first,ans.second)<<endl;
					}
				else{
					ans.second++;
					cout<<min(ans.first,ans.second)<<endl;
					}
			}
			else{
				if (z==n-1){
				if (s[z-1]=='1'){
					ans.first--;
					cout<<min(ans.first,ans.second)<<endl;
					}
				else{
					ans.second++;
					cout<<min(ans.first,ans.second)<<endl;
					}
				}
				else{
					if (s[z-1]=='1'){
						if (s[z+1]=='1'){
							ans.first--;
							ans.second--;
							cout<<min(ans.first,ans.second)<<endl;
							}
						else{
							cout<<min(ans.first,ans.second)<<endl;
							}

					}
					else{
						if (s[z+1]=='1'){
cout<<min(ans.first,ans.second)<<endl;
							}
						else{
							ans.first++;
							ans.second++;
cout<<min(ans.first,ans.second)<<endl;
							}
					}

			}

			}
		}
		else{
			s[z]='0';
			if (z==0){
				if (s[1]=='0'){
					ans.second--;
					cout<<min(ans.first,ans.second)<<endl;
					}
				else{
					ans.first++;
					cout<<min(ans.first,ans.second)<<endl;
					}
			}
			else{
				if (z==n-1){
					 if (s[z-1]=='1'){
						 ans.first++;
						 cout<<min(ans.first,ans.second);
					 }
					 else{
						 ans.second--;
						 cout<<min(ans.first, ans.second);
					 }
				}
			
				else{
				if (s[z-1]=='1'){
					if (s[z+1]=='1'){
						ans.second++;
						ans.first++;
						cout<<min(ans.first,ans.second)<<endl;
						}
					else{
						cout<<min(ans.first,ans.second)<<endl;
						}
				}
				else{
					if (s[z+1]=='1') cout<<min(ans.first,ans.second)<<endl;
					else{
						ans.first--;
						cout<<min(ans.first,ans.second)<<endl;
						}
				}
			}

		}
		}
	}
}
SubtaskSumTestVerdictTimeMemory
base10/50
1Accepted0/03ms1808 KiB
2Wrong answer0/04ms2084 KiB
3Accepted2/23ms2272 KiB
4Wrong answer0/23ms2520 KiB
5Wrong answer0/33ms2728 KiB
6Wrong answer0/33ms2940 KiB
7Wrong answer0/34ms3152 KiB
8Wrong answer0/34ms3364 KiB
9Accepted2/24ms3580 KiB
10Wrong answer0/24ms3664 KiB
11Wrong answer0/3499ms4320 KiB
12Wrong answer0/3500ms4548 KiB
13Accepted3/3284ms4608 KiB
14Wrong answer0/3504ms4632 KiB
15Accepted3/3479ms4788 KiB
16Wrong answer0/3291ms4944 KiB
17Wrong answer0/3501ms4904 KiB
18Wrong answer0/3486ms4900 KiB
19Wrong answer0/3467ms4952 KiB
20Wrong answer0/3291ms4956 KiB