# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60056 | Adhyyan1252 | Vudu (COCI15_vudu) | C++11 | 644 ms | 32020 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>
// 6 47
typedef long long ll;
#define NMAX 1000005
#define SMAX 2300000
using namespace std;
int bit[NMAX];
int n;
void add(int indx){
for(int i = indx; i <= n; i += (i&-i)){
bit[i] += 1;
}
}
ll query(int indx){
ll ans = 0;
for(int i = indx; i > 0; i -= (i&-i)){
ans += bit[i];
}
return ans;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
ll a[n];
for(int i = 0; i < n; i++){
cin>>a[i];
}
ll p; cin>>p;
vector<pair<ll, int> > vi;
ll zero = 0;
for(int i = n-1; i >= 0; i--){
a[i] -= p;
zero -= a[i];
ll cur = zero + a[i];
//cout<<i<<" PUSH: "<<cur<<endl;
vi.push_back({cur, i});
}
sort(vi.begin(), vi.end());
vector<int> indx(n);
for(int i = 0; i < n; i++){
indx[vi[i].second] = i;
}
ll ans = 0; zero = 0;
for(int i = n-1; i >= 0; i--){
add(indx[i]+1);
zero -= a[i];
pair<ll, int> temp = {zero, 0};
int index = lower_bound(vi.begin(), vi.end(), temp) - vi.begin();
ans += query(n) - query(index);
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |