# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37356 | IvanC | Vudu (COCI15_vudu) | C++14 | 536 ms | 30012 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>
#define LSOne(S) (S & (-S))
using namespace std;
typedef long long ll;
const ll MAXN = 1000010;
ll bit[MAXN],vetor[MAXN];
void update(ll pos){
while(pos < MAXN){
bit[pos]++;
pos += LSOne(pos);
}
}
ll read(ll pos){
ll ans = 0;
while(pos > 0){
ans += bit[pos];
pos -= LSOne(pos);
}
return ans;
}
vector<ll> comp;
int main(){
ll n;
scanf("%lld",&n);
comp.push_back(0);
for(ll i=1;i<=n;i++) scanf("%lld",&vetor[i]);
ll p;
scanf("%lld",&p);
ll soma = 0,resp = 0;
for(ll i=1;i<=n;i++){
soma += vetor[i];
soma -= p;
comp.push_back(soma);
}
sort(comp.begin(),comp.end());
comp.erase(unique(comp.begin(),comp.end()),comp.end());
soma = 0;
for(ll i=0;i<=n;i++){
soma += vetor[i];
if(i)soma -= p;
ll davez = lower_bound(comp.begin(),comp.end(),soma) - comp.begin() + 1;
resp += read(davez);
update(davez);
}
printf("%lld\n",resp);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |