# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1102507 | LTTrungCHL | Election (BOI18_election) | C++17 | 5 ms | 1108 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///***LTT***///
/// ->NHAT QUOC GIA<- ///
#include<bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
using namespace std;
vector <int> lg2;
//void MAKE_LOG_ARR(int n){
// lg2.resize(n + 3);
// for (int i = 1;i <= n;++i){
// lg2[i] = __lg(i);
// }
//}
const long long oo = 1e9+7;
const int N = 5 * 1e5 + 10;
int n, q, a[N];
string s;
namespace sub1{
int pre[2002], sur[2002], b[2002];
void solve(){
while (q--){
int l, r;
cin >> l >> r;
for (int i = l;i <= r;++i){
b[i] = a[i];
}
int ans = 0;
for (int i = l;i <= r;++i){
pre[i] = (i == l ? 0 : pre[i - 1] ) + b[i];
if (pre[i] < 0){
b[i] = 0;
++ans;
++pre[i];
}
}
for (int i = r;i >= l;--i){
sur[i] = (i == r ? 0 : sur[i + 1] ) + b[i];
if (sur[i] < 0){
b[i] = 0;
++ans;
++sur[i];
}
}
cout << ans <<"\n";
}
return;
}
};
void solve(){
cin >> n;
cin >> s;
for (int i = 0;i < s.size();++i){
if (s[i] == 'T'){
a[i + 1] = -1;
} else a[i + 1] = 1;
}
cin >> q;
if (n <= 2000 and q <= 2000){
sub1::solve();
return;
}
return;
}
int main(){
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
if (fopen("ltt.inp", "r")){
freopen("ltt.inp", "r", stdin);
freopen("ltt.out", "w", stdout);
}
// int t;
// cin >> t;
// while(t--){
solve();
// }
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |