Submission #1017452

#TimeUsernameProblemLanguageResultExecution timeMemory
1017452cnn008Mountains (NOI20_mountains)C++17
100 / 100
141 ms20236 KiB
#include "bits/stdc++.h" using namespace std; #ifdef N_N_C #include "debug.h" #else #define cebug(...) "Arya" #endif #define int long long const int N=3e5+5; const int mod=1e9+7; int n,a[N],l[N],r[N],ans; vector <int> compress; struct BIT{ #define gb(x) (x&(-x)) int n; vector <int> bit; void init(int _n){ bit.resize(_n,0); n=_n; } void update(int pos, int val){ int i=pos; for (; i<=n; i+=gb(i)) bit[i]+=val; } int get(int pos){ int ans=0,i=pos; for (; i>=1; i-=gb(i)) ans+=bit[i]; return ans; } }fwl,fwr; void sol(){ fwl.init(N); fwr.init(N); cin>>n; for(int i=1; i<=n; i++) cin>>a[i],compress.push_back(a[i]); sort(compress.begin(),compress.end()); compress.erase(unique(compress.begin(),compress.end()),compress.end()); for(int i=1; i<=n; i++) a[i]=lower_bound(compress.begin(),compress.end(),a[i])-compress.begin()+1; for(int i=1; i<=n; i++){ l[i]=fwl.get(a[i]-1); fwl.update(a[i],1); } for(int i=n; i>=1; i--){ r[i]=fwr.get(a[i]-1); fwr.update(a[i],1); ans+=r[i]*l[i]; } cout<<ans; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen(".inp", "r", stdin); // freopen(".out", "w", stdout); int tt=1; //cin>>tt; while(tt--){ sol(); } cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n"; return 0; } /** /\_/\ * (= ._.) * / >💖 \>💕 **/

Compilation message (stderr)

Mountains.cpp:67:9: warning: "/*" within comment [-Wcomment]
   67 | /**  /\_/\
      |
#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...