Submission #223808

#TimeUsernameProblemLanguageResultExecution timeMemory
223808bortozMountains (NOI20_mountains)C++17
100 / 100
493 ms31624 KiB
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define fi first #define se second constexpr int MAXN = 1 << 19; int fw[MAXN]; void add(int p, int v) { for (p++; p < MAXN; p += p & -p) { fw[p] += v; } } int sum(int p) { int r = 0; for (p++; p > 0; p -= p & -p) { r += fw[p]; } return r; } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<ll> V(N); map<ll, int> M; for (ll& i : V) { cin >> i; M[i] = 0; } int x = 0; for (auto& [k, v] : M) { v = x++; } for (ll& i : V) { i = M[i]; } vector<int> L(N), R(N); for (int i = 0; i < N; i++) { L[i] = sum(V[i] - 1); add(V[i], 1); } fill(fw, fw + MAXN, 0); for (int i = N - 1; i >= 0; i--) { R[i] = sum(V[i] - 1); add(V[i], 1); } ll res = 0; for (int i = 0; i < N; i++) { res += 1ll * L[i] * R[i]; } cout << res << endl; return 0; }

Compilation message (stderr)

Mountains.cpp: In function 'int main()':
Mountains.cpp:38:19: warning: unused variable 'k' [-Wunused-variable]
   for (auto& [k, v] : M) {
                   ^
#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...