# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165495 | egekabas | Vudu (COCI15_vudu) | C++14 | 1087 ms | 65540 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 ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
ll n, p;
int a[1000009];
set<ll> s;
map<ll, int> mpp; ll cur = 1;
int bit[1000009];
void upd(ll idx){
while(idx > 0){
bit[idx]++;
idx -= idx&(-idx);
}
}
ll get(ll idx){
ll ret = 0;
while(idx <= cur+2){
ret += bit[idx];
idx += idx&(-idx);
}
return ret;
}
int main() {
//freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%lld", &n);
for(ll i = 0; i < n; ++i){
scanf("%lld", &a[i]);
}
scanf("%lld", &p);
for(ll i = 0; i < n; ++i){
a[i] -= p;
}
ll add = 0;
for(ll i = 0; i < n; ++i){
//s.insert(-a[i]+add);
add -= a[i];
s.insert(a[i]+add);
}
for(auto u : s){
mpp[u] = cur++;
}
s.clear();
ll ans = 0;
add = 0;
for(ll i = 0; i < n; ++i){
if(a[i] >= 0){
++ans;
}
if(mpp.lower_bound(-a[i]+add) != mpp.end())
ans += get((*mpp.lower_bound(-a[i]+add)).ss);
add -= a[i];
upd(mpp[a[i]+add]);
}
printf("%lld", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |