Submission #1091568

#TimeUsernameProblemLanguageResultExecution timeMemory
1091568_rain_Mountains (NOI20_mountains)C++14
24 / 100
95 ms8180 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fixbug true const int maxn = 3e5; int h[maxn+2],BIT[maxn+2],ans[maxn+2],n; int Right[maxn+2],Left[maxn+2]; void add(int p , int val){ for (; p <= n; p += p&-p) BIT[p] += val; return; } int Get(int p){ int sum = 0; for (; p; p -= p&-p) sum += BIT[p]; return sum; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; vector<int>v; for (int i = 1; i <= n; ++i){ cin >> h[i]; v.push_back(h[i]); } sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end())-v.begin()); for (int i = 1; i <= n; ++i) h[i] = upper_bound(v.begin(),v.end(),h[i])-v.begin(); for (int i = 1; i <= n; ++i){ add(h[i],1); Left[i] += Get(h[i]-1); } memset(BIT,0,sizeof BIT); for (int i = n; i >= 1; --i){ add(h[i],1); Right[i] += Get(h[i]-1); } ll ans = 0; for (int i = 1; i <= n; ++i){ ans += (ll)Left[i]*Right[i]; } 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...