Submission #383312

#TimeUsernameProblemLanguageResultExecution timeMemory
383312MODDIMountains (NOI20_mountains)C++14
24 / 100
905 ms109780 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define mp make_pair #define pb push_back using namespace std; int n; vl arr; vector<ll> tree[12 * 100000]; void build(int node, int l, int r){ if(l == r) tree[node].pb(arr[l]); else{ int mid = (l + r) / 2; build(node * 2, l, mid); build(node * 2 + 1, mid + 1, r); merge(tree[node * 2].begin(), tree[node * 2].end(), tree[node * 2 + 1].begin(), tree[node * 2 + 1].end(), back_inserter(tree[node])); } } int query(int node, int l, int r, int L, int R, int k){ if(r < L || l > R) return 0; if(L <= l && r <= R){ return lower_bound(tree[node].begin(), tree[node].end(), k) -tree[node].begin(); } int mid = (l + r) / 2; int left = query(node * 2, l, mid, L, R, k), right = query(node * 2 + 1, mid + 1, r, L, R, k); return left + right; } int main(){ cin>>n; for(int i = 0; i < n; i++){ ll a; cin>>a; arr.pb(a); } build(1, 0, n - 1); ll rez = 0; for(int i =1; i < n - 1; i++){ ll left = query(1, 0, n - 1, 0, i, arr[i]); ll right = query(1, 0, n - 1, i, n - 1, arr[i]); if(left > 0 && right > 0) rez += (left * right); } cout<<rez<<endl; }
#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...