QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#696896#9155. 集合makrav100 ✓1233ms54664kbC++203.9kb2024-11-01 06:03:512024-11-01 06:03:52

Judging History

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

  • [2024-11-01 06:03:52]
  • 评测
  • 测评结果:100
  • 用时:1233ms
  • 内存:54664kb
  • [2024-11-01 06:03:51]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define int ll

mt19937 rnd(time(NULL));

struct Modular {
    int mod;
    Modular() = default;
    Modular(int md) {
        mod = md;
    }
    
    int sum(int x, int y) { return (x + y >= mod ? x + y - mod : x + y); }
    int diff(int x, int y) { return (x - y < 0 ? x - y + mod : x - y); }
    int mul(int x, int y) { return (x * y) % mod; }
    int binpow(int x, int y) {
        int ans = 1, pw = x;
        while (y) {
            if (y & 1) { ans = mul(ans, pw); }
            pw = mul(pw, pw);
            y >>= 1;
        }
        return ans;
    }
    int rev(int x) { return binpow(x, mod - 2); }
    int divide(int x, int y) { return mul(x, rev(y)); }
};

int sma[600010], smb[600010];

struct Hash {
    int n, m, mod;
    Modular M;

    vector<int> a, b, rval;
    int ha = 1, hb = 1, wsa, wsb;
    Hash() = default;
    Hash(int md, int n_, int m_, vector<int> a_, vector<int> b_) {
        n=n_;m=m_;mod=md;a=a_;b=b_;
        M = Modular(mod);
        rval.assign(n, 0);
        for (int i = 0; i < n; i++) rval[i] = rnd() % mod;
    }

    void add(int pos) {
        wsa = ha;
        wsb = hb;
        for (int j = 3 * pos; j < 3 * pos + 3; j++) {
            ha = M.divide(ha, max(sma[a[j]], 1ll));
            hb = M.divide(hb, max(smb[b[j]], 1ll));
            sma[a[j]] = M.sum(sma[a[j]], rval[pos]);
            smb[b[j]] = M.sum(smb[b[j]], rval[pos]);
            ha = M.mul(ha, max(sma[a[j]], 1ll));
            hb = M.mul(hb, max(smb[b[j]], 1ll));
        }
    }

    void undo(int pos) {
        ha = wsa; hb = wsb;
        for (int j = 3 * pos; j < 3 * pos + 3; j++) {
            sma[a[j]] = M.diff(sma[a[j]], rval[pos]);
            smb[b[j]] = M.diff(smb[b[j]], rval[pos]);
        }
    }

    void del(int pos) {
        for (int j = 3 * pos; j < 3 * pos + 3; j++) {
            ha = M.divide(ha, max(sma[a[j]], 1ll));
            hb = M.divide(hb, max(smb[b[j]], 1ll));
            sma[a[j]] = M.diff(sma[a[j]], rval[pos]);
            smb[b[j]] = M.diff(smb[b[j]], rval[pos]);
            ha = M.mul(ha, max(sma[a[j]], 1ll));
            hb = M.mul(hb, max(smb[b[j]], 1ll));
        }
    }

    bool check() {
        return ha == hb;
    }
};

signed main() {
    #ifdef LOCAL 
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cin.tie(nullptr)->sync_with_stdio(false);

    int n, m, q; cin >> n >> m >> q;
    vector<int> a(3 * n), b(3 * n);
    for (int i = 0; i < 3 * n; i++) {cin >> a[i]; a[i]--; }
    for (int &el : b) {cin >> el; el--;}

    int md1 = 1e9 + 7, md2 = 1e9 + 9;
    Hash h1(md1, n, m, a, b);
    int curr = -1;
    vector<int> maxr(n);

    for (int l = 0; l < n; l++) {
        while (curr + 1 < n) {
            h1.add(curr + 1);
            if (h1.check()) {
                curr++;
                continue;
            } else {
                h1.undo(curr + 1);
                break;
            }
        }
        maxr[l] = curr;
        if (curr >= l) {
            h1.del(l);
        }
        else {
            curr = l;
        }
    }

    h1 = Hash(md2, n, m, a, b);
    for (int l = 0; l < n; l++) {
        while (curr + 1 < n) {
            h1.add(curr + 1);
            if (h1.check()) {
                curr++;
                continue;
            } else {
                h1.undo(curr + 1);
                break;
            }
        }
        maxr[l] = min(maxr[l], curr);
        if (curr >= l) {
            h1.del(l);
        }
        else {
            curr = l;
        }
    }

    while (q--) {
        int l, r; cin >> l >> r;
        l--; r--;
        cout << (maxr[l] >= r ? "Yes\n" : "No\n");
    }
}

Details


Pretests

Pretest #1:

score: 5
Accepted
time: 1ms
memory: 3744kb

Pretest #2:

score: 5
Accepted
time: 1ms
memory: 3636kb

Pretest #3:

score: 5
Accepted
time: 1ms
memory: 3628kb

Pretest #4:

score: 5
Accepted
time: 1ms
memory: 3708kb

Pretest #5:

score: 5
Accepted
time: 1ms
memory: 3844kb

Pretest #6:

score: 5
Accepted
time: 1ms
memory: 3640kb

Pretest #7:

score: 5
Accepted
time: 2ms
memory: 3748kb

Pretest #8:

score: 5
Accepted
time: 2ms
memory: 3976kb

Pretest #9:

score: 5
Accepted
time: 20ms
memory: 3884kb

Pretest #10:

score: 5
Accepted
time: 20ms
memory: 3724kb

Pretest #11:

score: 5
Accepted
time: 1070ms
memory: 45448kb

Pretest #12:

score: 5
Accepted
time: 1059ms
memory: 45408kb

Pretest #13:

score: 5
Accepted
time: 14ms
memory: 3792kb

Pretest #14:

score: 5
Accepted
time: 7ms
memory: 3948kb

Pretest #15:

score: 5
Accepted
time: 104ms
memory: 4032kb

Pretest #16:

score: 5
Accepted
time: 108ms
memory: 3884kb

Pretest #17:

score: 5
Accepted
time: 102ms
memory: 7508kb

Pretest #18:

score: 5
Accepted
time: 107ms
memory: 8512kb

Pretest #19:

score: 5
Accepted
time: 1174ms
memory: 45480kb

Pretest #20:

score: 5
Accepted
time: 1217ms
memory: 54620kb

Final Tests

Test #1:

score: 5
Accepted
time: 1ms
memory: 3636kb

Test #2:

score: 5
Accepted
time: 1ms
memory: 3632kb

Test #3:

score: 5
Accepted
time: 1ms
memory: 3708kb

Test #4:

score: 5
Accepted
time: 1ms
memory: 3700kb

Test #5:

score: 5
Accepted
time: 1ms
memory: 3752kb

Test #6:

score: 5
Accepted
time: 1ms
memory: 3628kb

Test #7:

score: 5
Accepted
time: 1ms
memory: 3740kb

Test #8:

score: 5
Accepted
time: 1ms
memory: 3720kb

Test #9:

score: 5
Accepted
time: 16ms
memory: 3728kb

Test #10:

score: 5
Accepted
time: 20ms
memory: 3980kb

Test #11:

score: 5
Accepted
time: 1066ms
memory: 45508kb

Test #12:

score: 5
Accepted
time: 1071ms
memory: 45420kb

Test #13:

score: 5
Accepted
time: 11ms
memory: 3872kb

Test #14:

score: 5
Accepted
time: 11ms
memory: 3932kb

Test #15:

score: 5
Accepted
time: 103ms
memory: 3876kb

Test #16:

score: 5
Accepted
time: 111ms
memory: 3924kb

Test #17:

score: 5
Accepted
time: 107ms
memory: 7496kb

Test #18:

score: 5
Accepted
time: 103ms
memory: 8368kb

Test #19:

score: 5
Accepted
time: 1167ms
memory: 45492kb

Test #20:

score: 5
Accepted
time: 1233ms
memory: 54664kb

Extra Test:

score: 0
Extra Test Passed