Submission #433624

#TimeUsernameProblemLanguageResultExecution timeMemory
433624LouayFarahElection (BOI18_election)C++14
0 / 100
13 ms384 KiB
#include "bits/stdc++.h" using namespace std; #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) typedef long long ll; typedef string str; typedef double db; typedef long double ld; typedef pair<int, int> pi; #define fi first #define se second #define pb push_back #define mp make_pair #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define endl "\n" #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) const ll MOD = 1e9 + 7; //998244353 const ll INF = 1e18; const ll MX = 1e9 + 10; const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up #ifndef LOCAL #define cerr if(false) cerr #endif #define debug(x) cerr << #x << " : " << x << endl; #define debugs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl; #define debugv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl; #define here() cerr << "here" << endl; void IO() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } struct segtree { int size; vector<ll> sums; void init(int n) { size = 1; while(size<n) size*=2; sums.assign(2*size, 1e9); } void set(int i, int v, int x, int lx, int rx) { if(rx-lx==1) { sums[x] = v; return; } int mid = (lx+rx)/2; if(i<mid) set(i, v, 2*x+1, lx, mid); else set(i, v, 2*x+2, mid, rx); sums[x] = min(sums[2*x+1], sums[2*x+2]); } void set(int i, int v) { set(i, v, 0, 0, size); } ll sum(int l, int r, int x, int lx, int rx) { if(lx>=r||l>=rx) return 1e9; if(lx>=l&&rx<=r) return sums[x]; int mid = (lx+rx)/2; ll s1 = sum(l, r, 2*x+1, lx, mid); ll s2 = sum(l, r, 2*x+2, mid, rx); return min(s1, s2); } ll sum(int l, int r) { return sum(l, r, 0, 0, size); } }; int main() { boost; IO(); ll n; cin >> n; string s; cin >> s; ll q; cin >> q; while(q--) { ll l, r; cin >> l >> r; l--; vector<ll> pre(n); if(s[l]=='C') pre[l] = 1; else pre[l] = -1; FOR(i, l+1, r) { pre[i] = pre[i-1]; if(s[i]=='C') pre[i]+=1; else pre[i]-=1; } vector<ll> suff(n); if(s[r-1]=='C') suff[r-1] = 1; else suff[r-1] = -1; for(int i = r-2; i>=l; i--) { suff[i]+=suff[i+1]; if(s[i]=='C') suff[i] += 1; else suff[i]-=1; } ll min1 = 1e9, min2 = 1e9; for(int i = l; i<r; i++) { min1 = min(min1, pre[i]); min2 = min(min2, suff[i]); } ll res = min(min1, min2); if(res<0) cout << -res << endl; else cout << 0 << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...