QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370105#7782. Ursa Minor1234huangWA 2009ms27920kbC++205.7kb2024-03-28 21:56:272024-03-28 21:56:29

Judging History

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

  • [2024-03-28 21:56:29]
  • 评测
  • 测评结果:WA
  • 用时:2009ms
  • 内存:27920kb
  • [2024-03-28 21:56:27]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
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 = 1e9 + 19, mod2 = 1e9 + 789;

int n, m, q;

struct Barrate {
	__uint128_t m, t;
	void init(int _m) { m = _m, t = ((__uint128_t) 1 << 64) / m; }
	ll operator () (__uint128_t x) const { return x - m * (x * t >> 64); }
} pmod1, pmod2;

struct ull {
    int a, b;
    ull operator + (int &x) { return { pmod1(a + x), pmod2(b + x) }; }
    ull operator + (ull &x) { return { pmod1(a + x.a), pmod2(b + x.b) }; }
    ull operator + (const ull &x) { return { pmod1(a + x.a), pmod2(b + x.b) }; }
    ull operator += (ull &x) { return *this = *this + x; }

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

    ull operator * (const int &x) { return { pmod1(1ll * a * x), pmod2(1ll * b * x) }; }
    ull operator * (int &x) { return { pmod1(1ll * a * x), pmod2(1ll * b * x) }; }
    ull operator * (ull &x) { return { pmod1(1ll * a * x.a), pmod2(1ll * b * x.b) }; }
    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 base = { 131, 127 };
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";
	
    pmod1.init(mod1), pmod2.init(mod2);
    
    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;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5ms
memory: 10568kb

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: 0
Accepted
time: 624ms
memory: 12016kb

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: 668ms
memory: 24640kb

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: 653ms
memory: 19808kb

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: 2009ms
memory: 27920kb

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 40432nd words differ - expected: 'Yes', found: 'No'