Submission #224562

#TimeUsernameProblemLanguageResultExecution timeMemory
224562BertedMountains (NOI20_mountains)C++14
100 / 100
135 ms8808 KiB
#include <iostream> #include <vector> #include <algorithm> #define ll long long #define pii pair<ll, int> #define fst first #define snd second using namespace std; int n, fenwick[300001] = {}; vector<pii> dt; ll to = 0; int query(int x) { int to = 0; for (; x; x -= x & (-x)) {to += fenwick[x];} return to; } void upd(int x) { for (; x <= n; x += x & (-x)) {fenwick[x]++;} } int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) {ll x; cin >> x; dt.push_back({x, i + 1});} sort(dt.begin(), dt.end()); int i = 0; while (i < n) { to += (ll)query(dt[i].snd) * (i - query(dt[i].snd)); int j = i + 1; for (; j < n && dt[j].fst == dt[j - 1].fst; j++) {to += (ll)query(dt[j].snd) * (i - query(dt[j].snd));} for (; i < j; i++) {upd(dt[i].snd);} } cout << to << "\n"; 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...