Submission #795589

#TimeUsernameProblemLanguageResultExecution timeMemory
795589stefanneaguMountains (NOI20_mountains)C++17
2 / 100
62 ms5444 KiB
#include <iostream> #include <map> 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; } int 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...