31372023-02-19 13:15:11horvathabelSzínezéscpp17Wrong answer 25/50512ms4848 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--;
						ans.second--;
						cout<<min(ans.first,ans.second)<<endl;
						}
				}
			}

		}
		}
	}
}
SubtaskSumTestVerdictTimeMemory
base25/50
1Accepted0/03ms1808 KiB
2Accepted0/04ms2024 KiB
3Accepted2/23ms2228 KiB
4Wrong answer0/23ms2440 KiB
5Accepted3/33ms2648 KiB
6Accepted3/33ms2848 KiB
7Accepted3/34ms2940 KiB
8Wrong answer0/34ms3080 KiB
9Accepted2/24ms3192 KiB
10Wrong answer0/24ms3420 KiB
11Wrong answer0/3291ms4252 KiB
12Accepted3/3349ms4208 KiB
13Accepted3/3400ms4464 KiB
14Accepted3/3512ms4420 KiB
15Accepted3/3289ms4468 KiB
16Wrong answer0/3291ms4420 KiB
17Wrong answer0/3481ms4548 KiB
18Wrong answer0/3497ms4744 KiB
19Wrong answer0/3289ms4788 KiB
20Wrong answer0/3495ms4848 KiB