Submission #165505

# Submission time Handle Problem Language Result Execution time Memory
165505 2019-11-27T11:42:20 Z egekabas Vudu (COCI15_vudu) C++14
0 / 140
663 ms 31932 KB
#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;
ll a[1000009];
ll cur = 1;
ll bit[1000009];
vector<ll> v;
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){
        v.pb(-a[i]+add);    
        add -= a[i];
        v.pb(a[i]+add);    
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end())-v.begin());
    ll ans = 0;
    add = 0;
    for(ll i = 0; i < n; ++i){
        if(a[i] >= 0){
            ++ans;
        }
        ans += get(1+lower_bound(v.begin(), v.end(), -a[i]+add)-v.begin());
        add -= a[i];
        upd(1+lower_bound(v.begin(), v.end(), a[i]+add)-v.begin());
    }
    printf("%lld", ans);
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &n);
     ~~~~~^~~~~~~~~~~~
vudu.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &a[i]);
         ~~~~~^~~~~~~~~~~~~~~
vudu.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &p);
     ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 632 KB Output isn't correct
2 Incorrect 5 ms 632 KB Output isn't correct
3 Incorrect 5 ms 632 KB Output isn't correct
4 Incorrect 663 ms 30892 KB Output isn't correct
5 Incorrect 344 ms 21204 KB Output isn't correct
6 Incorrect 550 ms 27404 KB Output isn't correct
7 Incorrect 549 ms 28340 KB Output isn't correct
8 Incorrect 488 ms 24700 KB Output isn't correct
9 Incorrect 628 ms 31932 KB Output isn't correct
10 Incorrect 549 ms 27680 KB Output isn't correct