Submission #210727

#TimeUsernameProblemLanguageResultExecution timeMemory
210727grtMountains (NOI20_mountains)C++17
100 / 100
613 ms26748 KiB
#include <bits/stdc++.h> #define PB push_back #define ST first #define ND second #define _ ios_base::sync_with_stdio(0); cin.tie(0); //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); using namespace std; using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 300*1000+10; int n,nr; ll h[nax]; map<ll,int>sc; int T[(1<<20)],R; int l[nax]; void update(int a,int x) { a+=R; T[a]+=x; while(a>1) { a/=2; T[a] = T[2*a]+T[2*a+1]; } } int query(int a,int b) { a+=R; b+=R; if(a>b) return 0; int w = T[a]+(a!=b?T[b]:0); while(a/2!=b/2) { if(a%2==0) w+=T[a+1]; if(b%2==1) w+=T[b-1]; a/=2; b/=2; } return w; } ll ans; int main() {_ cin>>n; for(int i=1; i<=n; i++) { cin>>h[i]; sc[h[i]]; } for(auto &it:sc) it.ND = nr++; R=1; while(R<nr) R*=2; for(int i=1; i<=n; i++) h[i] = sc[h[i]]; for(int i=1; i<=n; i++) { l[i] = query(0,h[i]-1); update(h[i],1); } for(int i=1; i<2*R; i++) T[i] = 0; for(int i=n; i>=1; i--) { int x = query(0,h[i]-1); update(h[i],1); ans += (ll)l[i]*x; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...