31382023-02-19 13:17:52horvathabelSzínezéscpp17Accepted 50/50509ms5544 KiB

#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)<<endl;
					 }
					 else{
						 ans.second--;
						 cout<<min(ans.first, ans.second)<<endl;
					 }
				}
			
				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
base50/50
1Accepted0/03ms1816 KiB
2Accepted0/04ms2076 KiB
3Accepted2/23ms2284 KiB
4Accepted2/23ms2520 KiB
5Accepted3/33ms2748 KiB
6Accepted3/33ms2924 KiB
7Accepted3/34ms2912 KiB
8Accepted3/34ms2964 KiB
9Accepted2/24ms3036 KiB
10Accepted2/24ms3164 KiB
11Accepted3/3296ms4208 KiB
12Accepted3/3379ms4068 KiB
13Accepted3/3504ms4360 KiB
14Accepted3/3465ms4776 KiB
15Accepted3/3282ms5004 KiB
16Accepted3/3298ms5236 KiB
17Accepted3/3495ms5368 KiB
18Accepted3/3441ms5544 KiB
19Accepted3/3509ms5312 KiB
20Accepted3/3293ms5468 KiB