Submission #795596

#TimeUsernameProblemLanguageResultExecution timeMemory
795596stefanneaguMountains (NOI20_mountains)C++17
100 / 100
572 ms34064 KiB
#include <iostream> #include <map> #define int long long using namespace std; const int nmax = 3e5 + 7; int dr[nmax], st[nmax], f[nmax], v[nmax]; map<int, int> mp; void update(int i) { int val = 1; while(i < nmax) { f[i] += val; i += (i & (-i)); } } int query(int i) { int sum = 0; while(i > 0) { sum += f[i]; i -= (i & (-i)); } return sum; } int32_t main() { int n; cin >> n; for(int i = 1; i <= n; i ++) { cin >> v[i]; mp[v[i]]; } int cnt = 2; for(auto &it : mp) { it.second = cnt; cnt ++; } for(int i = 1; i <= n; i ++) { v[i] = mp[v[i]]; } for(int i = 1; i <= n; i ++) { dr[i] = query(v[i] - 1); update(v[i]); } for(int i = 0; i < nmax; i ++) { f[i] = 0; } for(int i = n; i >= 1; i --) { st[i] = query(v[i] - 1); update(v[i]); } long long ans = 0; for(int i = 1; i <= n; i ++) { ans += dr[i] * st[i]; } cout << ans; return 0; }
#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...