Submission #687570

#TimeUsernameProblemLanguageResultExecution timeMemory
687570ksjsjsjsjsjsjsMountains (NOI20_mountains)C++14
100 / 100
302 ms12496 KiB
#include <bits/stdc++.h> using namespace std; #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define ins insert #define ers erase #define bg begin #define ed end #define ft front #define bk back #define mtp make_tupl #define sz(x) (int)(x).size() #define all(x) (x).bg(), (x).ed() #define ll long long #define ull unsigned long long #define db double #define ldb long double #define str string #define pi pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define vpi vector<pi> #define vpll vector<pll> #define FOR(i, l, r) for (int i = (l); i <= (r); ++i) #define FOS(i, r, l) for (int i = (r); i >= (l); --i) #define FRN(i, n) for (int i = 0; i < (n); ++i) #define FSN(i, n) for (int i = (n) - 1; i >= 0; --i) #define EACH(i, x) for (auto &i : (x)) #define WHILE while template<typename T> T gcd(T a, T b) { WHILE(b) { a %= b; swap(a, b); } return a; } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } struct Fenwick { int n; vi f; Fenwick() {} Fenwick(int n) : n(n) { f.resize(n + 1, 0); } void upd(int pos, int v) { for (int i = pos; i <= n; i += (i & -i)) f[i] += v; } int get(int pos) { int rs = 0; for (int i = pos; i > 0; i -= (i & -i)) rs += f[i]; return rs; } }; const int N = 3e5 + 5; int n; ll h[N]; void compress() { vll v; FOR(i, 1, n) v.pb(h[i]); sort(all(v)); FOR(i, 1, n) h[i] = lb(all(v), h[i]) - v.bg() + 1; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> n; FOR(i, 1, n) cin >> h[i]; compress(); Fenwick f1(n), f2(n); FOR(i, 1, n) f2.upd(h[i], 1); ll rs = 0; FOR(i, 1, n) { f2.upd(h[i], -1); rs += 1LL * f1.get(h[i] - 1) * f2.get(h[i] - 1); f1.upd(h[i], 1); } cout << rs; // cerr << "\nTime: " << setprecision(5) << fixed << (ldb)clock() / CLOCKS_PER_SEC << "ms\n"; 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...