제출 #1232745

#제출 시각아이디문제언어결과실행 시간메모리
1232745AdnanboiElection (BOI18_election)C++20
0 / 100
2 ms320 KiB
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

void solve(){
	int n;
	cin>>n;
	string a;
	cin>>a;
	vector<int> nums(n);
	for(int i = 0; i < n; i++){
		if(a[i] == 'T') nums[i] = -1;
		else nums[i] = 1;
	}
	int q;
	cin>>q;
	while(q--){
		int l, r;
		cin>>l>>r;
		l--; r--;
		int ans1 = 0, ans2 = 0;
		int keep = 0;
		for(int i = l; i <= r; i++){
			keep += nums[i];
			if(keep < 0){
				keep = 0;
				ans1++;
			}
		}
		if(keep < 0){
			keep = 0;
			ans1++;
		}
		keep = 0;
		for(int i = r; i >= l; i--){
			keep += nums[i];
			if(keep < 0){
				keep = 0;
				ans2++;
			}
		}
		if(keep < 0){
			keep = 0;
			ans2++;
		}
		cout<<max(ans1, ans2)<<'\n';
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin>>t;
	while(t--){
		solve();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...