Submission #250399

#TimeUsernameProblemLanguageResultExecution timeMemory
250399apostoldaniel854Vudu (COCI15_vudu)C++14
126 / 140
300 ms37664 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb push_back #define dbg(x) cerr << #x << " " << x << "\n" const int N = 1e6; int n, p; int aib[1 + N]; int a[1 + N]; int val[1 + N]; inline int lsb (int x) { return x & -x; } int qry (int pos) { int ans = 0; while (pos) { ans += aib[pos]; pos -= lsb (pos); } return ans; } void upd (int pos, int val) { while (pos <= n) { aib[pos] += val; pos += lsb (pos); } } int main () { ios::sync_with_stdio (false); cin.tie (0); cout.tie (0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; cin >> p; vector <pair <ll, int>> v; v.pb ({0, 0}); ll sum = 0; for (int i = 1; i <= n; i++) { a[i] -= p; sum += a[i]; v.pb ({sum, i}); } sort (v.begin (), v.end ()); int cnt = 1; val[v[0].second] = cnt; for (int i = 1; i <= n; i++) { if (v[i].first != v[i - 1].first) cnt++; val[v[i].second] = cnt; } ll ans = 0; for (int i = 0; i <= n; i++) { ans += qry (val[i]); upd (val[i], 1); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...