Submission #250705

#TimeUsernameProblemLanguageResultExecution timeMemory
250705BlagojceMountains (NOI20_mountains)C++11
22 / 100
108 ms10952 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) #include <time.h> #include <cmath> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const int i_inf = 1e9; const ll inf = 1e18; const ll mod = 1000000007; const ld eps = 1e-13; const ld pi = 3.14159265359; mt19937 _rand(time(NULL)); clock_t timer = clock(); const int mxn = 5e5; const ll A = 911382323; const ll B = 972663749; ll modpow(ll x, ll n){ if(n == 0) return 1%mod; ll u = modpow(x, n/2); u = (u * u) % mod; if(n % 2) u = (u * x) % mod; return u; } ll inverse(ll x){ return modpow(x, mod-2); } ll add(ll ans, ll val){ ans = (ans + val) % mod; return ans; } ll mul(ll ans, ll val){ ans = (ans * val) % mod; return ans; } ll sub(ll ans, ll val){ ans = (ans - val) % mod; if(ans < 0) ans += mod; return ans; } ll _div(ll ans, ll val){ ans = (ans * inverse(val)) % mod; return ans; } ll fakt[mxn]; ll bc(ll n, ll k){ return (fakt[n]*inverse((fakt[k]*fakt[n-k])%mod))%mod; } ll sq(ll x){ return x*x; } ll rsum(ll a, ll b){ return (b-a+1)*(a+b)/2; } void prec(){ fakt[0] = 1; fr(i, 1, mxn){ fakt[i] = mul(fakt[i-1], i); } } int bit[mxn]; void update(int k, int val){ while(k < mxn){ bit[k] += val; k += k&-k; } } int sum(int k){ int s = 0; while(k > 0){ s += bit[k]; k -= k&-k; } return s; } void solve(){ int n; cin >> n; int a[n]; vector<pii> v; fr(i, 0, n){ cin >> a[i]; v.pb({a[i], i}); } sort(all(v)); int val = 0; int pr = -1; for(auto u : v){ if(u.st != pr) pr = u.st, ++val; a[u.nd] = val; } ll le[n]; ll ri[n]; fr(i, 0, n){ le[i] = sum(a[i]-1); update(a[i], +1); } fr(i, 0, n) update(a[i],-1); for(int i = n-1; i >= 0; i --){ ri[i] = sum(a[i]-1); update(a[i], +1); } ll ans = 0; fr(i, 0, n){ ans += le[i]*ri[i]; } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#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...