Submission #1132983

#TimeUsernameProblemLanguageResultExecution timeMemory
1132983MMJElection (BOI18_election)C++20
28 / 100
3095 ms1328 KiB
//#include<bits/stdc++.h> 
#include <cstdio>
#include <iostream>
using namespace std;
 
#pragma GCC optimize ("O3,unroll-loops")
#pragma GCC target ("tune=native,avx2")
//#pragma GCC optimize ("Ofast,unroll-loops,trapv")
//#pragma GCC target ("tune=native")
/*
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
 
#define f first
#define s second
#define mkpr make_pair
#define pque priority_queue
#define pb push_back
#define pf push_front
#define vec vector
#define pf push_front
#define Yes cout << "Yes\n";
#define YES cout << "YES\n";
#define No cout << "No\n";
#define NO cout << "NO\n";
#define em(x) (bool)(x).empty()
#define all(x) (x).begin(), (x).end()
#define tc int tc;cin >> tc; while(tc--) 
#define cps CLOCKS_PER_SEC
//setprecision
//int, vector<int>, greater<int>
 */
const int N = 5e5 + 5, P = 1e9 + 7;
 
int n, q;
char v[N];
int a[N], b[N];

int main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n >> v >> q;
	for (int i = 0; i < n; i++)
		if (v[i] == 'T')
			a[i] = 1;
		else
			a[i] = -1;
	int l, r, ans, x;
	while(q--) {
		cin >> l >> r;
		ans = x = 0; 
		l--;
		for (int i = l; i < r; i++) {
			x+=a[i];
			if (x > 0)
				ans++, b[i] = 0, x--;
			else
				b[i] = a[i];
		}
		x = ans; 
		for (int i = r - 1; i >= l; i--) {
			x+=b[i];
			ans = max(ans, x);
		}
		cout << ans << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...