QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#583720#9302. Caesar Cipherretired_midlightsWA 596ms23300kbC++143.7kb2024-09-22 21:33:112024-09-23 07:21:42

Judging History

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

  • [2024-11-04 17:10:09]
  • hack成功,自动添加数据
  • (/hack/1110)
  • [2024-10-21 09:47:48]
  • hack成功,自动添加数据
  • (/hack/1022)
  • [2024-10-21 09:39:50]
  • hack成功,自动添加数据
  • (/hack/1021)
  • [2024-10-21 09:31:34]
  • hack成功,自动添加数据
  • (/hack/1020)
  • [2024-10-03 10:14:59]
  • hack成功,自动添加数据
  • (/hack/928)
  • [2024-09-28 07:51:27]
  • hack成功,自动添加数据
  • (/hack/922)
  • [2024-09-28 07:42:39]
  • hack成功,自动添加数据
  • (/hack/921)
  • [2024-09-26 18:56:14]
  • hack成功,自动添加数据
  • (/hack/911)
  • [2024-09-23 07:21:42]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:WA
  • 用时:596ms
  • 内存:23300kb
  • [2024-09-23 07:21:34]
  • hack成功,自动添加数据
  • (/hack/885)
  • [2024-09-22 21:33:12]
  • 评测
  • 测评结果:100
  • 用时:655ms
  • 内存:23796kb
  • [2024-09-22 21:33:11]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i <= (int)b; i ++)
#define ll long long
#define ls p << 1
#define rs p << 1 | 1
using namespace std;

const int maxn = 500010;
int base = 19260817, mod = 1e9 + 7;

struct Info {
    int tag, mx, hsh;
} t[maxn << 2];

int n, q, a[maxn], power[maxn], sum[maxn];

void push_up(int p, int l, int r) {
    t[p].mx = max(t[ls].mx, t[rs].mx);
    int mid = (l + r) >> 1;
    t[p].hsh = (1ll * t[ls].hsh * power[r - mid] % mod + t[rs].hsh) % mod;
}

void build(int p, int l, int r) {
    t[p].tag = 0;
    if(l == r) {
        t[p].mx = t[p].hsh = a[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(ls, l, mid), build(rs, mid + 1, r);
    push_up(p, l, r);
}

void push_down(int p, int l, int r) {
    t[ls].tag += t[p].tag, t[rs].tag += t[p].tag;
    t[ls].mx += t[p].tag, t[rs].mx += t[p].tag;
    int mid = (l + r) >> 1;
    t[ls].hsh = (t[ls].hsh + 1ll * sum[mid - l] * t[p].tag % mod) % mod;
    t[rs].hsh = (t[rs].hsh + 1ll * sum[r - (mid + 1)] * t[p].tag % mod) % mod;
    t[p].tag = 0;
}

void modify_force(int p, int l, int r) {
    // cout << p << " " << l << " " << r << endl;
    if(l == r) {
        t[p].mx %= 65536;
        t[p].hsh = t[p].mx;
        return;
    }
    if(t[p].tag) push_down(p, l, r);
    int mid = (l + r) >> 1;
    if(t[ls].mx >= 65536) modify_force(ls, l, mid);
    if(t[rs].mx >= 65536) modify_force(rs, mid + 1, r);
    push_up(p, l, r);
}

void modify(int p, int l, int r, int ql, int qr) {
    if(ql <= l && r <= qr) {
        t[p].tag ++;
        t[p].mx ++;
        t[p].hsh = (t[p].hsh + sum[r - l]) % mod;
        if(t[p].mx >= 65536) {
            modify_force(p, l, r);
        }
        return;
    }
    if(t[p].tag) push_down(p, l, r);
    int mid = (l + r) >> 1;
    if(ql <= mid) modify(ls, l, mid, ql, qr);
    if(qr > mid) modify(rs, mid + 1, r, ql, qr);
    push_up(p, l, r);
}

int query(int p, int l, int r, int ql, int qr) {
    if(ql <= l && r <= qr) return t[p].hsh;
    int mid = (l + r) >> 1;
    if(t[p].tag) push_down(p, l, r);
    int res1 = 0, res2 = 0;
    if(ql <= mid) res1 = query(ls, l, mid, ql, qr);
    if(qr > mid) res2 = query(rs, mid + 1, r, ql, qr);
    // cout << p << " " << l << " " << r << " " << res1 << " " << res2 << endl;
    if(qr > mid) return (1ll * res1 * power[min(r, qr) - mid] % mod + res2) % mod;
    else return res1;
}

void solve() {
    int primes[] = { 100511, 100517, 100591, 100523 };
    srand((unsigned int) time(NULL));
    base = primes[rand() % 4];
    int mods[] = { 1000000007, 1000000009, 1000000033, 1000000123 };
    mod = mods[rand() % 4];
    cin >> n >> q;
    rep(i, 1, n) {
        cin >> a[i];
        assert(a[i] >= 0 && a[i] <= 65535);
    }
    power[0] = 1;
    rep(i, 1, n) power[i] = 1ll * power[i - 1] * base % mod;
    sum[0] = 1;
    rep(i, 1, n) sum[i] = (sum[i - 1] + power[i]) % mod;
    build(1, 1, n);
    while(q --) {
        int op, x, y, k;
        cin >> op >> x >> y;
        assert(op == 1 || op == 2);
        assert(x <= y && x >= 1 && y <= n);
        if(op == 1) modify(1, 1, n, x, y);
        else {
            cin >> k;
            assert(max(x, y) + k - 1 <= n);
            // cout << query(1, 1, n, x, x + k - 1) << endl;
            // cout << query(1, 1, n, y, y + k - 1) << "!" << endl;
            cout << (query(1, 1, n, x, x + k - 1) == query(1, 1, n, y, y + k - 1) ? "yes\n" : "no\n");
        }
    }
}

int main() {
    // freopen("G.in", "r", stdin);
    // freopen("G.out", "w", stdout);
    ios :: sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    // cin >> T;
    while(T --) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 9824kb

input:

5 6
1 2 1 2 1
2 1 2 2
2 1 3 3
1 1 1
1 3 5
2 1 2 4
2 1 2 2

output:

no
yes
no
yes

result:

ok 4 token(s): yes count is 2, no count is 2

Test #2:

score: 0
Accepted
time: 1ms
memory: 9916kb

input:

3 3
0 65535 65535
2 1 2 2
1 2 3
2 1 2 2

output:

no
yes

result:

ok 2 token(s): yes count is 1, no count is 1

Test #3:

score: 0
Accepted
time: 2ms
memory: 9780kb

input:

1000 1000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
...

result:

ok 1000 token(s): yes count is 1000, no count is 0

Test #4:

score: 0
Accepted
time: 93ms
memory: 12272kb

input:

100000 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
...

result:

ok 100000 token(s): yes count is 100000, no count is 0

Test #5:

score: 0
Accepted
time: 596ms
memory: 21948kb

input:

500000 500000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
...

result:

ok 500000 token(s): yes count is 500000, no count is 0

Test #6:

score: 0
Accepted
time: 546ms
memory: 21884kb

input:

500000 500000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
...

result:

ok 500000 token(s): yes count is 500000, no count is 0

Test #7:

score: 0
Accepted
time: 560ms
memory: 22844kb

input:

500000 500000
65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 65535 65534 6553...

output:

yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
no
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
yes
...

result:

ok 500000 token(s): yes count is 449947, no count is 50053

Test #8:

score: 0
Accepted
time: 561ms
memory: 22924kb

input:

500000 500000
49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 49999 49997 4999...

output:

yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
yes
yes
yes
yes
yes
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
yes
no
yes
y...

result:

ok 251941 token(s): yes count is 226844, no count is 25097

Test #9:

score: 0
Accepted
time: 576ms
memory: 22064kb

input:

500000 500000
65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 ...

output:

no
no
no
no
no
no
no
no
yes
no
no
yes
no
no
no
no
no
no
no
no
no
no
yes
yes
no
no
yes
no
no
yes
no
no
no
yes
no
no
no
no
no
no
no
yes
no
no
no
no
no
no
no
no
no
no
yes
no
no
no
no
no
no
yes
no
no
yes
no
no
no
no
no
no
no
no
no
yes
no
no
no
no
no
no
no
no
no
no
no
yes
yes
no
no
no
yes
no
no
no
no
yes...

result:

ok 251981 token(s): yes count is 32353, no count is 219628

Test #10:

score: 0
Accepted
time: 551ms
memory: 21804kb

input:

500000 500000
0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 65535 0 6553...

output:

yes
yes
yes
yes
no
no
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
yes
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
yes
yes
yes
yes
yes
yes
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
...

result:

ok 251952 token(s): yes count is 227079, no count is 24873

Test #11:

score: 0
Accepted
time: 546ms
memory: 22252kb

input:

500000 500000
2 1 2 3 1 2 3 2 3 3 3 2 3 2 2 3 3 1 1 2 1 1 3 1 2 2 1 2 1 2 3 1 1 3 2 2 3 3 3 1 3 1 2 3 3 3 3 1 1 3 1 1 3 2 2 3 1 3 1 2 1 1 1 3 2 1 1 2 3 1 3 3 1 3 2 2 3 3 2 3 2 1 3 2 3 3 2 3 1 1 2 1 3 3 3 2 1 2 1 1 1 1 3 1 3 1 1 3 2 1 3 2 1 1 3 3 1 3 1 3 1 2 2 1 1 1 2 2 1 1 1 3 3 1 2 3 3 2 1 3 3 1 2 ...

output:

no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
yes
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no...

result:

ok 251970 token(s): yes count is 4568, no count is 247402

Test #12:

score: 0
Accepted
time: 14ms
memory: 23300kb

input:

282544 1
0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 1...

output:

no

result:

ok NO

Extra Test:

score: -3
Extra Test Failed : Wrong Answer on 9
time: 0ms
memory: 9832kb

input:

400 4
1 15 21 1 2 9 12 9 23 15 21 1 21 18 1 1 10 1 1 1 1 1 19 14 22 1 1 1 6 20 1 5 21 1 8 17 1 1 8 1 1 1 1 1 1 1 21 1 1 18 18 1 1 21 1 1 1 1 1 1 1 8 1 1 17 8 1 21 5 1 20 6 1 1 1 22 14 19 1 1 1 1 1 10 1 1 18 21 1 21 15 23 9 12 9 2 1 21 15 1 1 1 16 1 1 1 23 7 1 1 6 17 19 1 7 1 1 1 1 15 1 23 15 15 1 1 ...

output:

yes
no
no
no

result:

wrong answer expected NO, found YES [1st token]