# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
219229 | gabrc52 | Vudu (COCI15_vudu) | C++14 | 504 ms | 43360 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cassert>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAXN=1e6;
int N;
int arr[MAXN];
int P;
ll ac[MAXN];
ll sum[MAXN];
ll dif[MAXN];
ll sorted[MAXN];
ll than;
ll ans;
ll ft[MAXN];
void inc(int i) {
for (; i < N; i |= i+1) ++ft[i];
}
int get(int i) {
int r = 0;
for (; i >= 0; i = (i&(i+1)) - 1) r += ft[i];
return r;
}
void remove(ll val) {
int lb = lower_bound(sorted,sorted+N,val) - sorted;
inc(lb);
}
int countLowerOrEqual(ll val) {
int ub = upper_bound(sorted,sorted+N,val) - sorted;
return ub - get(ub-1);
return 0;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>N;
for (int i=0; i<N; i++) {
cin>>arr[i];
}
cin>>P;
ac[0] = arr[0];
for (int i=1; i<N; i++) {
ac[i] = arr[i] + ac[i-1];
}
sum[0] = P;
sorted[0] = dif[0] = sum[0] - ac[0];
for (int i=1; i<=N; i++) {
sum[i] = sum[i-1] + P;
sorted[i] = dif[i] = sum[i] - ac[i];
}
sort(sorted, sorted+N);
than = 0;
ans += countLowerOrEqual(0);
for (int i=1; i<N; i++) {
remove(dif[i-1]);
than += P - arr[i-1];
ans += countLowerOrEqual(than);
}
cout<<ans<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |