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"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define mod 1000000007
ofstream fout(".out");
ifstream fin(".in");
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, q;
string st;
cin >> n >> st >> q;
int b[n] = {};
while(q--) {
int l, r;
cin >> l >> r;
l--;
r--;
int c = 0, ans = 0;
for(int i = l; i <= r; i++) {
if(st[i] == 'C')
c++;
else {
if(!c) {
b[i] = 1;
ans++;
}
else
c--;
}
}
c = 0;
for(int i = r; i >= l; i--) {
if(b[i]) {
b[i] = 0;
continue;
}
if(st[i] == 'C')
c++;
else {
if(!c)
ans++;
else
c--;
}
}
cout << ans << "\n";
}
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... |