Submission #439723

#TimeUsernameProblemLanguageResultExecution timeMemory
439723cpp219Election (BOI18_election)C++14
100 / 100
704 ms28004 KiB
#pragma GCC optimization O2 #pragma GCC optimization "unroll-loop" #pragma target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; typedef pair<ll,ll> LL; const ll N = 5e5 + 9; const ll inf = 1e9 + 7; string s; ll n,Q,l,r; struct Node{ ll pre,suf,sum,ans; }; Node st[4*N]; Node combine(Node L,Node R){ Node kq; kq.sum = L.sum + R.sum; kq.pre = max(L.pre,L.sum + R.pre); kq.suf = max(R.suf,R.sum + L.suf); kq.ans = max(L.pre + R.suf,max(L.ans + R.sum,L.sum + R.ans)); return kq; } void build(ll id,ll l,ll r){ if (l == r){ if (s[l] == 'C') st[id] = {0,0,-1,0}; else st[id] = {1,1,1,1}; return; } ll mid = (l + r)/2; build(id*2,l,mid); build(id*2 + 1,mid + 1,r); st[id] = combine(st[id*2],st[id*2 + 1]); } Node spare = {0,0,0,0}; Node Get(ll id,ll l,ll r,ll u,ll v){ if (v < l||r < u) return spare; if (u <= l&&r <= v) return st[id]; ll mid = (l + r)/2; return combine(Get(id*2,l,mid,u,v),Get(id*2 + 1,mid + 1,r,u,v)); } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n>>s; s = " " + s; build(1,1,n); cin>>Q; while(Q--){ cin>>l>>r; cout<<Get(1,1,n,l,r).ans<<"\n"; } }

Compilation message (stderr)

election.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
election.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
election.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
election.cpp: In function 'void build(int, int, int)':
election.cpp:34:9: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   34 |         else st[id] = {1,1,1,1}; return;
      |         ^~~~
election.cpp:34:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   34 |         else st[id] = {1,1,1,1}; return;
      |                                  ^~~~~~
election.cpp: In function 'int main()':
election.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...