QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#369973#7782. Ursa Minor1234huangWA 1236ms27732kbC++205.4kb2024-03-28 20:26:392024-03-28 20:26:39

Judging History

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

  • [2024-03-28 20:26:39]
  • 评测
  • 测评结果:WA
  • 用时:1236ms
  • 内存:27732kb
  • [2024-03-28 20:26:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
	while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int __stk[128], __top;
inline void write(int x) {
    if(x < 0) putchar('-'), x = -x;
	do { __stk[++__top] = x % 10, x /= 10; } while (x);
	while (__top) putchar(__stk[__top--] + '0');
}

const int mod = 998244353;

void Min(int &x, int y) { y < x and (x = y); }
void Max(int &x, int y) { y > x and (x = y); }

void inc(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = 1ll * x * y % mod; }

int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; }

bool stmer;

const int N = 2e5 + 10, M = 500, BL = 447;
const int mod1 = 998244353, mod2 = 1e9 + 7;
const int base = 127;

int n, m, q;

struct ull {
    int a, b;
    ull operator + (int &x) { return { (a + x) % mod1, (b + x) % mod2 }; }
    ull operator + (ull &x) { return { (a + x.a) % mod1, (b + x.b) % mod2 }; }
    ull operator += (ull &x) { return *this = *this + x; }

    ull operator - (int &x) { return { (a - x + mod1) % mod1, (b - x + mod2) % mod2 }; }
    ull operator - (ull &x) { return { (a - x.a + mod1) % mod1, (b - x.b + mod2) % mod2 }; }

    ull operator * (const int &x) { return { 1ll * a * x % mod1, 1ll * b * x % mod2 }; }
    ull operator * (int &x) { return { 1ll * a * x % mod1, 1ll * b * x % mod2 }; }
    ull operator * (ull &x) { return { 1ll * a * x.a % mod1, 1ll * b * x.b % mod2 }; }
    ull operator *= (ull &x) { return *this = *this * x; }

    ull operator = (const int &x) { return *this = { x, x }; }
    bool operator == (const ull &x) { return a == x.a and b == x.b; }
} emp;

ull a[N], b[N], s[N];

namespace ST {
    const int LG = 20;

    int lg[N], st[LG][N];

    void init() {
        for (int i = 2; i <= m; i++) lg[i] = lg[i >> 1] + 1;
        for (int i = 1; i < LG; i++) for (int j = 1; j + (1 << i) - 1 <= m; j++)
            st[i][j] = __gcd(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
    }

    int ask(int l, int r) {
        int h = lg[r - l + 1];
        return __gcd(st[h][l], st[h][r - (1 << h) + 1]);
    }
}

namespace Block1 {
    ull S1[M][M], S2[M][M];

    void init() {
        for (int bl = 1; bl < BL; bl++) for (int i = 1; i <= n; i++) {
            int id = i / BL; ull w = a[i] * b[i % bl];
            S1[bl][id] += w, S2[bl][id] += (i % bl ? emp : w);
        }
    }

    void modify(int p, ull v) {
        for (int bl = 1; bl < BL; bl++) {
            int id = p / BL; ull w = (v - a[p]) * b[p % bl];
            S1[bl][id] += w, S2[bl][id] += (p % bl ? emp : w);
        }
    }

    bool query(int l, int r, int k) {
        int L = l / BL + 1, R = r / BL - 1; ull res = { 0, 0 }, s0 = { 0, 0 }, w;
        for (int i = L; i <= R; i++) res += S1[k][i], s0 += S2[k][i];
        while (l <= min(L * BL - 1 , r)) res += (w = a[l] * b[l % k]), s0 += (l++ % k ? emp : w);
        while (r >= max(R * BL + BL, l)) res += (w = a[r] * b[r % k]), s0 += (r-- % k ? emp : w);
        return res == s0 * s[k - 1];
    }
}

namespace Block2 {
    ull S1[M][M], S2[M];

    void init() {
        for (int i = 1; i <= n; i++) {
            int id = i / BL;
            S2[id] += (S1[id][i % BL] = a[i] * b[i]);
        }
        for (int i = 0; i <= n / BL; i++) {
            for (int j = 1; j < BL; j++) S1[i][j] += S1[i][j - 1];
            if (i) S2[i] += S2[i - 1];
        }
    }

    void modify(int p, ull v) {
        int id = p / BL; ull w = (v - a[p]) * b[p];
        for (int i = p % BL; i < BL; i++) S1[id][i] += w;
        for (int i = id; i <= n / BL; i++) S2[i] += w;
    }

    ull ask(int l, int r) {
        ull res = (r < BL ? emp : S2[r / BL - 1]) - (l < BL ? emp : S2[l / BL - 1]);
        return res + S1[r / BL][r % BL] - (l % BL ? S1[l / BL][l % BL - 1] : emp); 
    }

    bool query(int l, int r, int k) {
        ull res = { 0, 0 }, s0 = { 0, 0 };
        while (l <= r) res = res * b[k] = ask(l, l + k - 1), s0 += a[l], l += k;
        return res == s0 * s[k - 1] * b[l - k];
    }
}

bool edmer;
signed main() {
	// freopen("gym104869F.in", "r", stdin);
	// freopen("gym104869F.out", "w", stdout);
	cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";
	
    n = read(), m = read(), q = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    for (int i = 1; i <= m; i++) ST :: st[0][i] = read();
    
    ST :: init(), b[0] = s[0] = 1;
    for (int i = 1; i < N; i++) s[i] = s[i - 1] + (b[i] = b[i - 1] * base);

    Block1 :: init(), Block2 :: init();
    while (q--) {
        char ch = getchar();
        while (ch != 'U' and ch != 'Q') ch = getchar();
        if (ch == 'U') {
            int p = read(); ull v = { read(), 0 }; v.b = v.a;
            Block1 :: modify(p, v), Block2 :: modify(p, v), a[p] = v;
        }
        else {
            int l = read(), r = read(), s = read(), t = read();
            int k = __gcd(r - l + 1, ST :: ask(s, t));
            if (k < BL) puts(Block1 :: query(l, r, k) ? "Yes" : "No");
            else puts(Block2 :: query(l, r, k) ? "Yes" : "No");
        }
    }

    cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n";
	return 0;
} 

詳細信息

Test #1:

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

input:

6 4 5
1 1 4 5 1 4
3 3 2 4
Q 1 5 1 2
Q 2 5 3 4
U 5 2
Q 1 6 1 2
Q 2 5 3 4

output:

Yes
No
No
Yes

result:

ok 4 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 10580kb

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: 0
Accepted
time: 422ms
memory: 10724kb

input:

2000 2000 200000
1 1 2 0 0 2 0 2 0 0 0 0 0 2 2 1 2 0 0 2 2 2 1 0 1 2 1 2 0 0 1 1 1 2 0 0 2 2 2 2 0 2 0 0 2 1 2 0 0 1 2 2 1 0 2 0 0 0 1 2 2 1 2 2 0 0 1 1 1 0 0 2 0 0 1 1 0 2 2 2 1 0 0 1 0 1 2 2 2 1 1 2 2 1 2 1 0 2 2 3 1 3 2 3 1 0 1 2 0 1 1 1 0 2 2 3 2 0 3 2 3 3 1 2 3 1 2 0 1 0 3 1 0 0 2 0 1 2 1 3 2 2...

output:

Yes
Yes
No
Yes
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
No
No
No
No
No
Yes
No
No
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Yes
No
No
Yes
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No...

result:

ok 100554 tokens

Test #4:

score: 0
Accepted
time: 439ms
memory: 24384kb

input:

1 200000 200000
998244353
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

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 100240 tokens

Test #5:

score: 0
Accepted
time: 420ms
memory: 19324kb

input:

6 131072 200000
0 0 0 0 1000000000 1000000000
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...

output:

Yes
Yes
Yes
No
No
No
Yes
No
No
No
No
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
No
No
No
No
No
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
No
Yes
Yes
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
Yes
No
No
No
No
No
No
Yes
Yes
No
Yes
N...

result:

ok 100021 tokens

Test #6:

score: -100
Wrong Answer
time: 1236ms
memory: 27732kb

input:

200000 200000 200000
490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
Yes
Yes
No
No
No
No
No
No
No
No
Yes
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
Yes
No
Yes
Yes
No
No
No
No
No
No
No
No
N...

result:

wrong answer 22818th words differ - expected: 'Yes', found: 'No'