Submission #526758

#TimeUsernameProblemLanguageResultExecution timeMemory
526758beepbeepsheepIzbori (COCI22_izbori)C++17
15 / 110
26 ms5020 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<ll,ll> #define endl '\n' const ll inf=1e15; const ll mod=1e9+7; const ll maxn=2e5+5; ll arr[maxn]; vector<ll> v; ll fen[2*maxn]; void upd(ll pos){ while (pos<2*maxn){ fen[pos]++; pos+=(pos&-pos); } } ll query(ll pos){ ll ans=0; while (pos){ ans+=fen[pos]; pos-=(pos&-pos); } return ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin>>n; for (int i=0;i<n;i++){ cin>>arr[i]; } ll ans=0; for (int i=1;i<=2;i++){ ll tot=0; memset(fen,0,sizeof(fen)); upd(2e5+1); for (int j=0;j<n;j++){ if (arr[j]==i){ tot++; }else{ tot--; } upd(tot+2e5+1); ans+=query(tot+2e5); } } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...