QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#369952#7782. Ursa Minor1234huangWA 0ms14644kbC++204.5kb2024-03-28 20:01:032024-03-28 20:01:04

Judging History

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

  • [2024-03-28 20:01:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:14644kb
  • [2024-03-28 20:01:03]
  • 提交

answer

#include <bits/stdc++.h>
#define ull unsigned 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 ull base = 127;

int n, m, q;

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 ? 0 : 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 ? 0 : w);
        }
    }

    bool query(int l, int r, int k) {
        int L = l / BL + 1, R = r / BL - 1; ull res = 0, s0 = 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 ? 0 : w);
        while (r >= max(R * BL + BL, l)) res += (w = a[r] * b[r % k]), s0 += (r-- % k ? 0 : 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 * b[p] - 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 ? 0 : S2[r / BL - 1]) - (l < BL ? 0 : S2[l / BL - 1]);
        return res + S1[r / BL][r % BL] - (l % BL ? S1[l / BL][l % BL - 1] : 0); 
    }

    bool query(int l, int r, int k) {
        ull res = 0, s0 = 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(), v = read();
            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));
            cout << l << ' ' << r << ' ' << k << '\n';
            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: 0
Wrong Answer
time: 0ms
memory: 14644kb

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:

1 5 1
Yes
2 5 2
No
1 6 3
No
2 5 2
Yes

result:

wrong answer 1st words differ - expected: 'Yes', found: '1'