Submission #1088260

#TimeUsernameProblemLanguageResultExecution timeMemory
1088260nguyen31hoang08minh2003Vudu (COCI15_vudu)C++17
140 / 140
240 ms33460 KiB
#include <bits/stdc++.h> #define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define ford(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define fi first #define se second #define pb push_back #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using ld = long double; template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;}; template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;}; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; struct FenwickTree { int n; vi bit; void resize(int newN) { n = newN; bit.resize(n + 1); } void update(int x, int val) { for (; x <= n; x += x & -x) bit[x] += val; }; int query(int x) const { int res = 0; for (; x > 0; x -= x & -x) res += bit[x]; return res; } }; /* (a[l] + ... + a[r]) / (r - l + 1) >= p a[l] + ... + a[r] >= p * (r - l + 1) (a[l] - p) + ... + (a[r] - p) >= 0 prefix[r] - prefix[l - 1] >= 0 prefix[r] >= prefix[l - 1] */ const int maxN = 1000005; int n, p, a[maxN]; ll prefix[maxN]; void Input() { cin >> n; fort(i, 1, n) cin >> a[i]; cin >> p; } void Solve() { vector<ll> h(1, 0); FenwickTree bit; ll res = 0; fort(i, 1, n) { prefix[i] = prefix[i - 1] + a[i] - p; h.pb(prefix[i]); } sort(all(h)); h.erase(unique(all(h)), h.end()); bit.resize(h.size()); bit.update((lower_bound(all(h), 0) - h.begin()) + 1, 1); for (int i = 1, j; i <= n; ++i) { j = (lower_bound(all(h), prefix[i]) - h.begin()) + 1; res += bit.query(j); bit.update(j, 1); } cout << res << '\n'; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); Input(); Solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...