Submission #566052

#TimeUsernameProblemLanguageResultExecution timeMemory
566052shrimbElection (BOI18_election)C++17
82 / 100
68 ms19048 KiB
#pragma GCC optimize ("Ofast") #pragma GCC target ("avx,avx2,fma") #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; template<class x> using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>; #define int long long #define endl '\n' #define mod 1000000007 //\ #define mod 1686876991 const int maxn = 200001; const int N = exp2(ceil(log2(maxn))); int Left, Right; struct node { int sum; int mp, ms; int ans; }; node operator +(const node a, const node b) { node c; c.sum = a.sum + b.sum; c.mp = max(a.mp, b.mp + a.sum); c.ms = max(b.ms, a.ms + b.sum); c.ans = max({a.mp + b.ms, b.ans + a.sum, a.ans + b.sum}); return c; } node seg[2 * N]; node Query (int l = 1, int r = N, int ind = 1) { if (l > Right || r < Left) assert(0); if (l >= Left and r <= Right) return seg[ind]; int m = (l + r) / 2; if (Left > m) return Query(m + 1, r, ind * 2 + 1); if (Right <= m) return Query(l, m, ind * 2); return Query(l, m, ind * 2) + Query(m + 1, r, ind * 2 + 1); } signed main () { cin.tie(0)->sync_with_stdio(0); int n, q; string s; cin >> n >> s >> q; for (int i = 0 ; i < n ; i++) { if (s[i] == 'T') { seg[N + i] = {1, 1, 1, 1}; } else { seg[N + i] = {-1, 0, 0, 0}; } } for (int i = N - 1 ; i ; i--) seg[i] = seg[i * 2] + seg[i * 2 + 1]; while (q--) { cin >> Left >> Right; cout << Query().ans << endl; } }

Compilation message (stderr)

election.cpp:17:1: warning: multi-line comment [-Wcomment]
   17 | //\
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...