Submission #950316

#TimeUsernameProblemLanguageResultExecution timeMemory
950316BzslayedMountains (NOI20_mountains)C++17
2 / 100
661 ms50648 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define pff pair<float, float> #define coutpair(p) cout << p.first << " " << p.second << "\n" typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; ll h[n]; for (int i=0; i<n; i++) cin >> h[i]; ordered_set lcnt, rcnt; //to check for bottom values ll left[n], right[n]; //for a fixed point i, how many numbers are //smaller than it on each side left[0] = 0, right[n-1] = 0; ll ans = 0; lcnt.insert(h[0]); for (int i=1; i<n; i++){ left[i] = lcnt.order_of_key(h[i]); lcnt.insert(h[i]); } rcnt.insert(h[n-1]); for (int i=n-2; i>=0; i--){ right[i] = rcnt.order_of_key(h[i]); ans += left[i]*right[i]; rcnt.insert(h[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...