# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
313878 | BeanZ | Vudu (COCI15_vudu) | C++14 | 390 ms | 27532 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.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
ll a[N], st[N];
ll n;
void add(ll x){
for (; x <= n; x += (x & -x)){
st[x]++;
}
}
ll get(ll x){
ll res = 0;
for (; x > 0; x -= (x & -x)){
res = res + st[x];
}
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
ll p;
cin >> p;
for (int i = 1; i <= n; i++) a[i] -= p;
vector<ll> val;
ll sum = 0;
val.push_back(sum);
for (int i = 1; i <= n; i++){
sum = sum + a[i];
val.push_back(sum);
}
sort(val.begin(), val.end());
val.resize(unique(val.begin(), val.end()) - val.begin());
add(lower_bound(val.begin(), val.end(), 0) - val.begin() + 1);
sum = 0;
ll ans = 0;
for (int i = 1; i <= n; i++){
sum = sum + a[i];
ll id = lower_bound(val.begin(), val.end(), sum) - val.begin() + 1;
ans = ans + get(id);
add(id);
}
cout << ans;
}
/*
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |