QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#724228#1964. Stock Price PredictionAMATSUKAZE#WA 369ms71472kbC++204.5kb2024-11-08 11:06:162024-11-08 11:06:16

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 11:06:16]
  • 评测
  • 测评结果:WA
  • 用时:369ms
  • 内存:71472kb
  • [2024-11-08 11:06:16]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define all(v) begin(v),end(v)
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; }


template<class S, auto op, auto e> struct segtree {
    int n, sz;
    vector<S> d;
    void upd(int k) { d[k] = op(d[2*k], d[2*k+1]); }
    segtree(int _n = 0) : segtree(vector<S>(_n, e())) {}
    segtree(vector<S> v) : n(v.size()) {
        sz = bit_ceil((uint32_t)n);
        d = vector<S>(sz*2, e());
        rep(i,0,n) d[sz+i] = v[i];
        for (int i=sz-1; i>=1; i--) upd(i);
    }
    S prod(int l, int r){
        S sml = e(), smr = e();
        l +=sz, r += sz;
        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);
    }
    void set(int p, S x){
        p += sz;
        d[p] = x;
        while (p >>= 1) upd(p);
    }
    S get(int p) { return d[p+sz];}
    int max_right(int l, auto f) {
        if (l == n) return n;
        l += sz;
        S sm = e();
        do {
            while(l % 2 == 0) l >>= 1;
            if(!f(op(sm,d[l]))) {
                while(l < sz) {
                    l <<= 1;
                    if (f(op(sm,d[l]))) { sm = op(sm, d[l++]);}
                }
                return l - sz;
            }
            sm = op(sm, d[l++]);
        } while((l&-l)!=l);
        return n;
    }

    int min_left(int r, auto f) {
        if (r == 0) return 0;
        r += sz;
        S sm = e();
        do {
            r--;
            while(r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while(r < sz) {
                    r = 2 * r + 1;
                    if (f(op(d[r],sm))) {
                        sm = op(d[r--], sm);
                    }
                }
                return r + 1 - sz;
            }
            sm = op(d[r],sm);
        }while((r&-r)!=r);
        return 0;
    }
};

using pii = pair<int,int>;

vector<int> preproc(vector<int> a){
    int n = a.size();
    vector<pii> b(n);
    rep(i,0,n){
        b[i] = pii(a[i],i);
    }
    sort(all(b));
    vector<int> inv(n);
    rep(i,0,n){
        inv[b[i].second] = i;
    }
    return inv;
}

using ull = unsigned long long;
const ull M = (1ULL << 61) - 1;


ull mul(ull a, ull b){
    return __uint128_t(a) * b % M;
}
ull add(ull a, ull b){
    a += b;
    if (a >= M) a -= M;
    return a;
}

struct S {
    ull h;
    int len;
};

vector<ull> pows;
ull base = 0;
void init(){
    base = random_device()() + (1ULL << 31);
    const int mx = 2e6;
    pows.resize(mx);
    pows[0] = 1;
    rep(i,1,mx){
        pows[i] = mul(pows[i-1],base);
    }
}

S op(S a, S b){
    return S{add(mul(a.h,pows[b.len]),b.h),a.len+b.len};
}
S e(){
    return S{0,0};
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a){
    if (a.empty()) return os;
    os << a.front();
    for (auto &e : a | views::drop(1)){
        os << ' ' << e;
    }
    return os;
}

void solve(){
    init();
    int m, n; cin >> m >> n;
    vector<int> a = [&]{
        vector<int> v(m);
        rep(i,0,m){
            cin >> v[i];
        }
        return preproc(v);
    }();
    // cout << a << endl;
    vector<int> b = [&]{
        vector<int> v(n);
        rep(i,0,n){
            cin >> v[i];
        }
        return preproc(v);
    }();
    // cout << b << endl;
    auto val = [&](int x){
        return S{ull(x),1};
    };
    ull ha = [&]{
        vector<int> ia(m);
        rep(i,0,m){
            ia[a[i]] = i;
        }
        S h = e();
        rep(i,0,m){
            h = op(h,val(ia[i]));
        }
        return h.h;
    }();
    ull geta = [&]{
        S h = e();
        rep(i,0,m){
            h = op(h,val(1));
        }
        return h.h;
    }();
    vector<int> ans;
    segtree<S,op,e> seg(n);
    rep(i,0,m-1){
        seg.set(b[i],val(i));
    }
    rep(i,m-1,n){
        seg.set(b[i],val(i));
        ull hb = seg.prod(0,n).h;
        if (ha == hb){
            ans.emplace_back(i-m+2);
        }
        seg.set(b[i-(m-1)],e());
        ha = add(ha,geta);
    }
    if (ans.empty()){
        cout << 0 << endl;
        return ;
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 369ms
memory: 71472kb

input:

10000 1000000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:

ok single line: '1 2 3 4 5 6 7 8 9 10 11 12 13 ...997 989998 989999 990000 990001'

Test #2:

score: -100
Wrong Answer
time: 355ms
memory: 71228kb

input:

10000 1000000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

1 2 10002 20002 30002 40002 50002 60002 70002 80002 90002 100002 110002 120002 130002 140002 150002 160002 170002 180002 190002 200002 210002 220002 230002 240002 250002 260002 270002 280002 290002 300002 310002 320002 330002 340002 350002 360002 370002 380002 390002 400002 410002 420002 430002 4400...

result:

wrong answer 1st lines differ - expected: '2 10002 20002 30002 40002 5000...002 950002 960002 970002 980002', found: '1 2 10002 20002 30002 40002 50...002 950002 960002 970002 980002'