이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define pb push_back
#define endl '\n'
#define fi first
#define se second
#define CDIV(a,b) (((a)+(b)-(1))/(b))
using ll = long long;
using ld = long double;
const ll inf = 1e9 + 37;
const ll mod = 1e9 + 7;
const ll N = 5e5 + 37;
const ld eps = 1e-9;
const ld PI = acos((ld)-1);
template<typename T, size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<T, N>& a);
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p);
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s);
template<typename T, typename cmp>
std::ostream& operator<<(std::ostream& os, const std::set<T, cmp>& s);
template<typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void solve(){
int n;
string s;
cin >> n >> s;
int Q;
cin >> Q;
while(Q--) {
int l, r;
cin >> l >> r;
string tmp = s.substr(l - 1, r - l + 1);
// cout << tmp << ' ';
int ans = 0, count = 0;
for(char& c : tmp) {
assert(count >= 0);
if(c == 'C') {
count++;
continue;
}
if(c != 'C' and c != 'T') {
continue;
}
if(count == 0) {
c = 'X';
ans++;
}
else {
count--;
}
}
reverse(tmp.begin(), tmp.end());
count = 0;
for(char& c : tmp) {
assert(count >= 0);
if(c == 'C') {
count++;
continue;
}
if(c != 'C' and c != 'T') {
continue;
}
if(count == 0) {
c = 'X';
ans++;
}
else {
count--;
}
}
reverse(tmp.begin(), tmp.end());
// cout << tmp << ' ';
cout << ans << endl;
}
}
signed main(){
std::ios_base::sync_with_stdio(0);
std::cin.tie(NULL);
// signed t; cin >> t; while(t--)
solve();
}
template<typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for(T& x : v)
is >> x;
return is;
}
template<typename T, size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<T, N>& a) {
os << "[";
for(size_t i = 0; i + 1 < N; ++i) {
os << a[i] << ", ";
}
if(N > 0)
os << a[N - 1];
os << "]";
return os;
}
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
os << "(" << p.first << ", " << p.second << ") ";
return os;
}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
os << '[';
for(auto x : v)
os << x << ", ";
os << "] ";
return os;
}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
os << "{";
for(auto x : s)
os << x << ", ";
os << "} ";
return os;
}
//
template<typename T, typename cmp>
std::ostream& operator<<(std::ostream& os, const std::set<T, cmp>& s) {
os << "{";
for(auto x : s)
os << x << ", ";
os << "} ";
return os;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |