Submission #298989

# Submission time Handle Problem Language Result Execution time Memory
298989 2020-09-14T11:50:25 Z ToMmyDong Rice Hub (IOI11_ricehub) C++17
49 / 100
53 ms 3064 KB
#include <bits/extc++.h>
#include <ext/pb_ds/tag_and_trait.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
#define ALL(i) i.begin(),i.end()
#define SZ(i) int(i.size())
#define X first
#define Y second
#define eb emplace_back
#define pb push_back
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream& printRng (ostream& os, IT bg, IT ed) {
    os << "{";
    for (IT it=bg; it!=ed; it++) {
        if (it == bg) os << *it;
        else os << "," << *it;
    }
    return os << "}";
}
template<typename T> ostream& operator << (ostream& os, const vector<T>& v) {return printRng(os,ALL(v));}
#else
#define debug(...)
#endif
#include "ricehub.h"

int n;
ll b;
vector<int> pos, pid;


struct Bit {
    int N;
    vector<ll> bit;
    Bit (int sz) : N(sz+3), bit(sz+3) {}
    void add (int x, ll val) {
        for (x++; x<N; x+=-x&x) {
            bit[x] += val;
        }
    }
    ll qry (int x) {
        ll res = 0;
        for (x++; x; x-=-x&x) {
            res += bit[x];
        }
        return res;
    }
};

bool check (int len) {
    Bit sum(n);
    for (int i=0; i<n; i++) {
        sum.add(i, pos[i]);
        if (i >= len - 1) {
            int pmid = i - len/2;
            ll L = 1LL*pos[pmid]*(len-len/2) - sum.qry(pmid);
            ll R = sum.qry(n) - sum.qry(pmid) - 1LL*pos[pmid]*(len/2);
            if (L + R < b) {
                return true;
            }

            sum.add(i-len+1, -pos[i-len+1]);
        }
    }
    return false;
}

int besthub(int R, int L, int X[], long long B) {
    n = R;
    b = B;
    for (int i=0; i<R; i++) {
        pos.eb(X[i]);
    } 

    int l = 1, r = R + 1;
    while (l < r - 1) {
        int m = (l + r) >> 1;
        if (check(m)) {
            l = m;
        } else {
            r = m;
        }
    }

    return l;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Incorrect 0 ms 256 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 896 KB Output is correct
2 Correct 18 ms 896 KB Output is correct
3 Correct 48 ms 3064 KB Output is correct
4 Correct 48 ms 3064 KB Output is correct
5 Correct 44 ms 1532 KB Output is correct
6 Correct 42 ms 1532 KB Output is correct
7 Correct 53 ms 2800 KB Output is correct
8 Correct 44 ms 2808 KB Output is correct
9 Correct 41 ms 1532 KB Output is correct
10 Correct 40 ms 1532 KB Output is correct
11 Correct 47 ms 3064 KB Output is correct
12 Correct 48 ms 3056 KB Output is correct
13 Correct 44 ms 1660 KB Output is correct
14 Correct 43 ms 1660 KB Output is correct
15 Correct 35 ms 2424 KB Output is correct
16 Correct 35 ms 2424 KB Output is correct
17 Correct 42 ms 2808 KB Output is correct
18 Correct 42 ms 2800 KB Output is correct
19 Correct 46 ms 2928 KB Output is correct
20 Correct 46 ms 2928 KB Output is correct