Submission #223803

#TimeUsernameProblemLanguageResultExecution timeMemory
223803bortozMountains (NOI20_mountains)C++17
24 / 100
239 ms12300 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<int> V(N); map<int, int> M; for (int& i : V) { cin >> i; M[i] = 0; } int x = 0; for (auto& p : M) { p.second = x++; } for (int& 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; }
#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...