Submission #541000

#TimeUsernameProblemLanguageResultExecution timeMemory
541000bayemirovMountains (NOI20_mountains)C++17
100 / 100
906 ms21908 KiB
// bayemirov #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef tree< ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int N = 4e5; int n; ll h[N], ans; ordered_set a, b; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> h[i]; if (i > 1) b.insert(h[i]); } a.insert(h[0]); for (int i = 1; i < n; i++) { int cnt_x = a.order_of_key(h[i]); int cnt_z = b.order_of_key(h[i]); //cout << i << ' ' << cnt_x << ' ' << cnt_z << "\n"; ans += cnt_x*1ll*cnt_z; a.insert(h[i]); b.erase(b.find_by_order(b.order_of_key(h[i+1]))); } 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...