Submission #1092023

#TimeUsernameProblemLanguageResultExecution timeMemory
1092023underwaterkillerwhaleMountains (NOI20_mountains)C++17
100 / 100
72 ms14164 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define rep(i,m,n) for(int i=(m); i<=(n); i++) #define reb(i,m,n) for(int i=(m); i>=(n); i--) #define iter(id, v) for(auto id : v) #define fs first #define se second #define MP make_pair #define pb push_back #define bit(msk, i) ((msk >> i) & 1) #define SZ(v) (ll)v.size() #define ALL(v) v.begin(),v.end() using namespace std; mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count()); ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); } const int N = 3e5 + 2; const int Mod = 1e9 + 7; const ll INF = 1e16; const ll BASE = 137; const int szBL = 350; struct fenwick_Tree { int m; int fen[N]; void init (int n) { m = n; } void update (int pos, int val) { for (; pos <= m; pos += pos & -pos) fen[pos] += val; } int get (int pos) { int res = 0; for (;pos > 0; pos -= pos & -pos) res += fen[pos]; return res; } int get (int u, int v) { if (u > v) return 0; return get(v) - get(u - 1); } }BIT; int n; ll a[N]; pll b[N]; void solution () { cin >> n; rep (i, 1, n) cin >> a[i]; BIT.init(n); rep (i, 1, n) b[i] = MP(a[i], i); sort (b + 1, b + 1 + n); ll res = 0; rep (i, 1, n) { int L = i, R = i; while (R < n && b[R].fs == b[R + 1].fs) ++R; rep (j, L, R) { int val, pos; tie(val, pos) = b[j]; res += 1LL * BIT.get(1, pos - 1) * BIT.get(pos + 1, n); } rep (j, L, R) { int val, pos; tie(val, pos) = b[j]; BIT.update(pos, 1); } i = R; } cout << res <<"\n"; } #define file(name) freopen(name".inp","r",stdin); \ freopen(name".out","w",stdout); int main () { // file("DTREE"); ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0); int num_Test = 1; // cin >> num_Test; while (num_Test--) solution(); } /* no bug +5 */
#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...