Submission #329178

#TimeUsernameProblemLanguageResultExecution timeMemory
329178oakMountains (NOI20_mountains)C++14
100 / 100
561 ms28780 KiB
#include<bits/stdc++.h> #define si 300000 using namespace std; int fw[si+1]; long long arr[si+1],db[si+1],sum[si+1]; void upd(int po,int val){ for(;po<=si;po+=(po&-po)){ fw[po]+=val; } } int qry(int po){ int ret = 0; for(;po>=1;po-=(po&-po)){ ret += fw[po]; } return ret; } int main(){ int n,j,i; scanf("%d",&n); map<long long,int> mp; int rl[n]; for(i=0;i<n;i++){ scanf("%lld",&arr[i]); db[i] = arr[i]; } sort(db,db+n); int co = 1; for(i=0;i<n;i++){ if(mp.find(db[i]) != mp.end())continue; mp[db[i]] = co; co++; } for(i=0;i<n;i++){ rl[i] = mp[arr[i]]; } for(i=0;i<n;i++){ sum[i] = qry(rl[i]-1); upd(rl[i],1); } long long ans = 0; memset(fw,0,sizeof fw); for(i=n-1;i>=0;i--){ sum[i] *= qry(rl[i]-1); upd(rl[i],1); ans += sum[i]*1ll; } printf("%lld",ans); }

Compilation message (stderr)

Mountains.cpp: In function 'int main()':
Mountains.cpp:19:8: warning: unused variable 'j' [-Wunused-variable]
   19 |  int n,j,i;
      |        ^
Mountains.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
Mountains.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |   scanf("%lld",&arr[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~
#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...