Submission #287121

#TimeUsernameProblemLanguageResultExecution timeMemory
287121sabamakuMountains (NOI20_mountains)C++14
0 / 100
2079 ms2936 KiB
#include<bits/stdc++.h> using namespace std; int n,x,p[3][200005],ans,d[200005],sum,sum1,s[200005]; map <long long,int> mp; void update(int a){ for(int i = a; i <= n; i += (i & -i)){ p[x][i]++; } } void deleteit(int a){ for(int i = a; i <= n; i += (i & -i)){ p[1][i]--; } } void solve(int a){ sum = 0; for(int i = a - 1; i >= 1; i -= (i & -i)){ sum += p[x][i]; } } int main(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> d[i]; s[i] = d[i]; } sort(s + 1, s + n + 1); for(int i = 1; i <= n; i++){ if(mp[s[i]] == 0){ x++; mp[s[i]] = x; } } x = 1; for(int i = n; i >= 2; i--){ update(mp[d[i]]); } for(int i = 2; i < n; i++){ deleteit(mp[d[i]]); x = 0; update(mp[d[i - 1]]); x = 1; solve(mp[d[i]]); sum1 = sum; x = 0; solve(mp[d[i]]); ans += sum * sum1; //cout << sum << " " << sum1 << " " << mp[d[i]] << endl; } cout << ans << endl; }
#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...