# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100851 | dalgerok | Vudu (COCI15_vudu) | C++17 | 421 ms | 29736 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<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, p, t[N];
long long a[N], b[N];
inline int get(int pos){
int cur = 0;
for(int i = pos; i >= 0; i &= i + 1, i--){
cur += t[i];
}
return cur;
}
inline int upd(int pos){
for(int i = pos; i <= n; i |= i + 1){
t[i] += 1;
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
cin >> p;
a[0] = -p;
b[0] = -p;
for(int i = 1; i <= n; i++){
a[i] -= p;
a[i] += a[i - 1];
b[i] = a[i];
}
sort(b, b + n + 1);
long long ans = 0;
upd(lower_bound(b, b + n + 1, -p) - b);
for(int i = 1; i <= n; i++){
a[i] = lower_bound(b, b + n + 1, a[i]) - b;
ans += get(a[i]);
upd(a[i]);
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |