This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int maxn = 5e5 + 12;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
void solve() {
int n, q;
string s;
cin >> n >> s >> q;
while(q--) {
int l, r;
cin >> l >> r;
int t = 0, ans = 0;
for(int i = l - 1; i < r; i++) {
if(s[i] == 'T'){
if(t == 0)s[i] = '!', ans++;
else t--;
}
else t++;
}
t = 0;
for(int i = r - 1; i >= l - 1; i--) {
if(s[i] == 'T'){
if(t == 0)ans++;
else t--;
}
else if(s[i] == 'C')t++;
else s[i] = 'T';
}
cout << ans << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int tcs = 1;
//cin >> tcs;
for(int i = 1; i <= tcs; i++) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |