Submission #337660

#TimeUsernameProblemLanguageResultExecution timeMemory
337660Vladth11Mountains (NOI20_mountains)C++14
100 / 100
215 ms18204 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define debug(x) cerr << #x << " " << x << "\n" #define debug_with_space(x) cerr << #x << " " << x << " " using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair <ll, ll> pii; typedef pair <ll, pii> piii; typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> OST; const ll NMAX = 300001; const ll INF = 1e9; const ll MOD = 1000000007; const ll BLOCK = 101; const ll nr_of_bits = 35; struct ura{ ll i, v, idx; } v[NMAX]; bool cmp(ura a, ura b){ return a.i < b.i; } bool cmpp(ura a, ura b){ return a.idx < b.idx; } ll st[NMAX], n, dr[NMAX]; ll aib[NMAX + 5]; void update(ll x, ll val){ for(ll i = x; i <= n; i += i&(-i)) aib[i] += val; } ll query(ll x){ ll val = 0; for(ll i = x; i > 0; i -= i&(-i)) val += aib[i]; return val; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll i; cin >> n; for(i = 1; i <= n; i++){ cin >> v[i].i; v[i].idx = i; } ll cnt = 1; sort(v + 1, v + n + 1, cmp); for(i = 1; i <= n; i++){ if(i > 1 && v[i].i != v[i - 1].i) cnt++; v[i].v = cnt; } sort(v + 1, v + n + 1, cmpp); for(i = 1; i <= n; i++){ update(v[i].v, 1); st[i] = query(v[i].v - 1); } ll sol = 0; for(i = 1; i <= n; i++){ update(v[i].v, -1); } for(i = n; i >= 1; i--){ update(v[i].v, 1); dr[i] = query(v[i].v - 1); sol += 1LL * st[i] * dr[i]; } cout << sol; 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...