Submission #165485

# Submission time Handle Problem Language Result Execution time Memory
165485 2019-11-27T11:28:05 Z egekabas Vudu (COCI15_vudu) C++14
0 / 140
207 ms 14020 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<int, int>  pii;
typedef pair<ld, ld>  pld;
int n, p;
int a[1000009];
set<int> s;
map<int, int> mpp; int cur = 1;
int bit[1000009];
void upd(int idx){
    while(idx > 0){
        bit[idx]++;
        idx -= idx&(-idx);
    }
}
int get(int idx){
    int 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(int i = 0; i < n; ++i){
        scanf("%lld", &a[i]);
    }
    scanf("%lld", &p);
    for(int i = 0; i < n; ++i){
        a[i] -= p;
    }
    
    int add = 0;
    for(int 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(int i = 0; i < n; ++i){
        if(a[i] >= 0){
            ++ans;
        }
        ans += get(mpp[-a[i]+add]);
        add -= a[i];
        upd(mpp[a[i]+add]);
        
    }
    printf("%lld", ans);
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:38:21: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
     scanf("%lld", &n);
                   ~~^
vudu.cpp:40:28: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
         scanf("%lld", &a[i]);
                       ~~~~~^
vudu.cpp:42:21: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
     scanf("%lld", &p);
                   ~~^
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 3 ms 376 KB Output isn't correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Incorrect 3 ms 376 KB Output isn't correct
4 Incorrect 207 ms 13448 KB Output isn't correct
5 Incorrect 102 ms 7672 KB Output isn't correct
6 Incorrect 158 ms 11884 KB Output isn't correct
7 Incorrect 163 ms 12444 KB Output isn't correct
8 Incorrect 147 ms 10748 KB Output isn't correct
9 Incorrect 196 ms 14020 KB Output isn't correct
10 Incorrect 159 ms 12152 KB Output isn't correct