Submission #825526

#TimeUsernameProblemLanguageResultExecution timeMemory
825526boyliguanhanElection (BOI18_election)C++17
100 / 100
1541 ms187688 KiB
#include<bits/stdc++.h> using namespace std; struct Data { int l=0,r=0,s=0,a=0; Data():l(0){} Data(bool b) : l(b), r(b), s(b?1:-1), a(b){} Data(Data a, Data b) : l(max(a.l, a.s+b.l)), r(max(b.r,b.s+a.r)), s(a.s+b.s), a(max(max(a.a+b.s, b.a+a.s), a.l+b.r)){} }; vector<vector<Data>> tb(500100, vector<Data>(20)); int main() { int n, q; string str; cin >> n >> str >> q; for(int i = 1; i <= n; i++) { tb[i][0] = Data(str[i-1]=='T'); } for(int j = 1; j < 20; j++) for(int i = 1; i < n-(1<<j)+2; i++) tb[i][j] = Data(tb[i][j-1], tb[i+(1<<j-1)][j-1]); while(q--){ Data d; int a, b; cin >> a >> b; for(int i = 20;i--;) if(a+(1<<i)-2<b) d = Data(d,tb[a][i]), a+=(1<<i); cout << d.a << '\n'; } }

Compilation message (stderr)

election.cpp: In function 'int main()':
election.cpp:19:51: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   19 |             tb[i][j] = Data(tb[i][j-1], tb[i+(1<<j-1)][j-1]);
      |                                                  ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...