QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#836187#9920. Money Game 2ucup-team055#WA 0ms3824kbC++208.5kb2024-12-28 17:13:462024-12-28 17:14:01

Judging History

This is the latest submission verdict.

  • [2024-12-31 22:17:02]
  • hack成功,自动添加数据
  • (/hack/1322)
  • [2024-12-31 21:57:13]
  • hack成功,自动添加数据
  • (/hack/1321)
  • [2024-12-28 17:14:01]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3824kb
  • [2024-12-28 17:13:46]
  • Submitted

answer

#line 1 "a.cpp"
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(b<a){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;}
template<class T> void vec_out(vector<T> &p,int ty=0){
    if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
    else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}


#include <algorithm>
#include <cassert>
#include <functional>
#include <vector>


#ifdef _MSC_VER
#include <intrin.h>
#endif

#if __cplusplus >= 202002L
#include <bit>
#endif

namespace atcoder {

namespace internal {

#if __cplusplus >= 202002L

using std::bit_ceil;

#else

// @return same with std::bit::bit_ceil
unsigned int bit_ceil(unsigned int n) {
    unsigned int x = 1;
    while (x < (unsigned int)(n)) x *= 2;
    return x;
}

#endif

// @param n `1 <= n`
// @return same with std::bit::countr_zero
int countr_zero(unsigned int n) {
#ifdef _MSC_VER
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
#else
    return __builtin_ctz(n);
#endif
}

// @param n `1 <= n`
// @return same with std::bit::countr_zero
constexpr int countr_zero_constexpr(unsigned int n) {
    int x = 0;
    while (!(n & (1 << x))) x++;
    return x;
}

}  // namespace internal

}  // namespace atcoder


namespace atcoder {

#if __cplusplus >= 201703L

template <class S, auto op, auto e> struct segtree {
    static_assert(std::is_convertible_v<decltype(op), std::function<S(S, S)>>,
                  "op must work as S(S, S)");
    static_assert(std::is_convertible_v<decltype(e), std::function<S()>>,
                  "e must work as S()");

#else

template <class S, S (*op)(S, S), S (*e)()> struct segtree {

#endif

  public:
    segtree() : segtree(0) {}
    explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
    explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {
        size = (int)internal::bit_ceil((unsigned int)(_n));
        log = internal::countr_zero((unsigned int)size);
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) const {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r) const {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() const { return d[1]; }

    template <bool (*f)(S)> int max_right(int l) const {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) const {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*f)(S)> int min_left(int r) const {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) const {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    std::vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};

}  // namespace atcoder


const int D = 35;


struct F{
    ll val = -1;
    ll rem = -1;
    ll len = -1;
};

F e(){
    return F{};
}

ll safe_mul(ll a, ll b){
    if (a <= ILL / b) return a * b;
    return ILL;
}

F op(F L, F R){
    if (L.rem == -1) return R;
    if (R.rem == -1) return L;
    if (R.len <= D){
        R.val += (L.val >> R.len);
        if (R.rem <= L.val % (1ll << R.len)){
            R.val++;
            R.rem = (1ll << R.len) - (L.val % (1ll << R.len)) + R.rem;
        }
        else R.rem -= (L.val) % (1ll << R.len);
    }
    else if (R.rem <= L.val){
        R.val++;
        R.rem = INF;
    }
    else{
        R.rem -= L.val;
    }
    // R.rem = ((R.rem - 1) * (1ll << L.len)) + L.rem;
    if (R.rem == 1){
        R.rem = L.rem;
    }
    else if (L.len >= D){
        R.rem = ILL;
    }
    else{
        R.rem = min(ILL, safe_mul(R.rem - 1, 1ll << L.len) + L.rem);
    }
    R.len += L.len;
    return R;
}

F opsw(F L, F R){
    return op(R, L);
}

ll target;

bool f(F x){
    return x.val < target;
}

void solve();
// CITRUS CURIO CITY / FREDERIC
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    rep(i, 0, t) solve();
}

void solve(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, 0, N) cin >> A[i];
    vector<F> base(N);
    rep(i, 0, N) base[i] = {A[i], 2, 1};
    rep(i, 0, N * 2) base.push_back(base[i]);
    atcoder::segtree<F, op, e> seg1(base);
    atcoder::segtree<F, opsw, e> seg2(base);
    auto safe_add = [&](int a, int b) -> int {
        return ((a + b) % N + N) % N;
    };
    vector<ll> ans(N);
    rep(i, 0, N){
        if (N >= D * 2 + 1){
            target = seg1.prod(i + N - D, i + N + 1).val;
            ans[i] += target;
            int L1 = seg1.min_left<f>(i + N + 1) - 1;
            target++;
            int L2 = seg1.min_left<f>(i + N + 1) - 1;
            target = seg2.prod(i + N + 1, i + N + D).val;
            ans[i] += target;
            int R1 = seg2.max_right<f>(i + N) + 1;
            target++;
            int R2 = seg2.max_right<f>(i + N) + 1;
            if (R2 - L2 <= N) ans[i] += 2;
            else if (R2 - L1 <= N) ans[i] += 1;
            else if (R1 - L2 <= N) ans[i] += 1;
            else assert(R1 - L1 <= N);
        }
        else{
            rep(j, i + 1, i + N + 1){
                chmax(ans[i], seg1.prod(j, i + N + 1).val + seg2.prod(i + N, j + N).val);
            }
        }
        ans[i] -= A[i];
    }
    vec_out(ans);
    auto tmp = seg1.all_prod();
    cout << tmp.rem << " " << tmp.val <<  " " << tmp.len << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3824kb

input:

3
5
2 1 4 3 5
5
2 1 3 1 2
1
1000000000

output:

6 5 7 8 8
8 7 15
4 4 5 4 4
12688 3 15
1000000000
8 1750000000 3

result:

wrong answer 6th numbers differ - expected: '4', found: '8'