QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#688244#9155. 集合nor100 ✓708ms19732kbC++172.0kb2024-10-30 01:27:552024-10-30 01:27:57

Judging History

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

  • [2024-10-30 01:27:57]
  • 评测
  • 测评结果:100
  • 用时:708ms
  • 内存:19732kb
  • [2024-10-30 01:27:55]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;

ll pw(ll b, ll e) {
    ll r = 1;
    while (e) {
        if (e & 1) {
            r = r * b % MOD;
        }
        b = b * b % MOD;
        e >>= 1;
    }
    return r;
}

ll inv(ll b) { return pw(b, MOD - 2); }

const int MAX_N = 2e5 + 5, MAX_M = 6e5 + 5;
vector<int> cs[2];
ll tot_hash[2] = {1, 1};
ll mask_hash[2][MAX_M];
ll pow2[MAX_N];

void sub_tot(ll &tot, ll mask) {
    tot *= inv(mask + 1);
    tot %= MOD;
}

void add_tot(ll &tot, ll mask) {
    tot *= mask + 1;
    tot %= MOD;
}

void toggle_idx(int idx, bool add) {
    for (int k = 0; k < 3; k++) {
        for (int t = 0; t < 2; t++) {
            int val = cs[t][3 * idx + k];
            ll &mask = mask_hash[t][val];
            sub_tot(tot_hash[t], mask);
            mask += add ? pow2[idx] : MOD - pow2[idx];
            if (mask >= MOD) {
                mask -= MOD;
            }
            add_tot(tot_hash[t], mask);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m, q;
    cin >> n >> m >> q;
    pow2[0] = 1;
    for (int i = 1; i < n; i++) {
        pow2[i] = pow2[i - 1] << 1;
        if (pow2[i] >= MOD) {
            pow2[i] -= MOD;
        }
    }
    for (int t = 0; t < 2; t++) {
        cs[t].resize(3 * n);
        for (int &c : cs[t]) {
            cin >> c;
        }
    }
    vector<int> max_r(n);
    int r_ptr = 0;
    for (int i = 0; i < n; i++) {
        while (r_ptr < n && tot_hash[0] == tot_hash[1]) {
            toggle_idx(r_ptr++, true);
        }
        if (tot_hash[0] != tot_hash[1]) {
            toggle_idx(--r_ptr, false);
        }
        max_r[i] = r_ptr;
        toggle_idx(i, false);
    }
    for (int qi = 0; qi < q; qi++) {
        int a, b;
        cin >> a >> b;
        cout << (max_r[a - 1] >= b ? "Yes\n" : "No\n");
    }

    return 0;
}

詳細信息


Pretests

Pretest #1:

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

Pretest #2:

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

Pretest #3:

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

Pretest #4:

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

Pretest #5:

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

Pretest #6:

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

Pretest #7:

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

Pretest #8:

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

Pretest #9:

score: 5
Accepted
time: 19ms
memory: 3648kb

Pretest #10:

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

Pretest #11:

score: 5
Accepted
time: 578ms
memory: 10176kb

Pretest #12:

score: 5
Accepted
time: 570ms
memory: 10332kb

Pretest #13:

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

Pretest #14:

score: 5
Accepted
time: 6ms
memory: 3732kb

Pretest #15:

score: 5
Accepted
time: 97ms
memory: 3712kb

Pretest #16:

score: 5
Accepted
time: 109ms
memory: 3736kb

Pretest #17:

score: 5
Accepted
time: 56ms
memory: 3920kb

Pretest #18:

score: 5
Accepted
time: 57ms
memory: 4968kb

Pretest #19:

score: 5
Accepted
time: 681ms
memory: 11212kb

Pretest #20:

score: 5
Accepted
time: 692ms
memory: 19732kb

Final Tests

Test #1:

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

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

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

Test #10:

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

Test #11:

score: 5
Accepted
time: 579ms
memory: 10240kb

Test #12:

score: 5
Accepted
time: 579ms
memory: 12020kb

Test #13:

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

Test #14:

score: 5
Accepted
time: 6ms
memory: 3796kb

Test #15:

score: 5
Accepted
time: 101ms
memory: 3644kb

Test #16:

score: 5
Accepted
time: 109ms
memory: 3732kb

Test #17:

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

Test #18:

score: 5
Accepted
time: 55ms
memory: 4736kb

Test #19:

score: 5
Accepted
time: 663ms
memory: 11396kb

Test #20:

score: 5
Accepted
time: 708ms
memory: 19636kb

Extra Test:

score: 0
Extra Test Passed