QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#826929#9774. Same Sumucup-team2179#WA 1289ms40732kbC++233.1kb2024-12-22 17:22:482024-12-22 17:22:49

Judging History

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

  • [2025-01-11 11:59:18]
  • hack成功,自动添加数据
  • (/hack/1443)
  • [2024-12-23 17:02:06]
  • hack成功,自动添加数据
  • (/hack/1310)
  • [2024-12-23 16:48:26]
  • hack成功,自动添加数据
  • (/hack/1309)
  • [2024-12-23 16:33:45]
  • hack成功,自动添加数据
  • (/hack/1308)
  • [2024-12-23 16:23:53]
  • hack成功,自动添加数据
  • (/hack/1307)
  • [2024-12-23 16:13:08]
  • hack成功,自动添加数据
  • (/hack/1306)
  • [2024-12-23 15:54:42]
  • hack成功,自动添加数据
  • (/hack/1305)
  • [2024-12-23 14:58:39]
  • hack成功,自动添加数据
  • (/hack/1304)
  • [2024-12-23 09:58:11]
  • hack成功,自动添加数据
  • (/hack/1302)
  • [2024-12-23 09:47:22]
  • hack成功,自动添加数据
  • (/hack/1301)
  • [2024-12-23 09:41:23]
  • hack成功,自动添加数据
  • (/hack/1300)
  • [2024-12-23 09:26:32]
  • hack成功,自动添加数据
  • (/hack/1299)
  • [2024-12-23 09:19:58]
  • hack成功,自动添加数据
  • (/hack/1298)
  • [2024-12-23 09:13:29]
  • hack成功,自动添加数据
  • (/hack/1297)
  • [2024-12-22 18:52:18]
  • hack成功,自动添加数据
  • (/hack/1296)
  • [2024-12-22 18:13:14]
  • hack成功,自动添加数据
  • (/hack/1294)
  • [2024-12-22 17:22:49]
  • 评测
  • 测评结果:WA
  • 用时:1289ms
  • 内存:40732kb
  • [2024-12-22 17:22:48]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ll __int128_t
#define db double
#define pii pair<int, int>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 998244353, base = 131;
int arr[maxn];
int ksm(int a, int b) {
    int res = 1;
    for (; b; b >>= 1, a = a * a % mod)
        if (b & 1) res = res * a % mod;
    return res;
}
struct Node {
    ll laz, sum, pos, neg;
};
struct SEG {
#define ls rt << 1
#define rs rt << 1 | 1 
#define mid ((l + r) >> 1)
    Node t[maxn << 2];
    void push_up(int rt) {
        t[rt].sum = t[ls].sum + t[rs].sum;
        t[rt].pos = (t[ls].pos + t[rs].pos) % mod;
        t[rt].neg = (t[ls].neg + t[rs].neg) % mod;
    }
    void fun(int rt, int l, int r, int k) {
        t[rt].sum += (r - l + 1) * k;
        int tem = ksm(base, k);
        t[rt].pos = (t[rt].pos * tem) % mod;
        t[rt].neg = (t[rt].neg * ksm(tem, mod - 2)) % mod;
        t[rt].laz += k;
    }
    void push_down(int rt, int l, int r) {
        if (t[rt].laz) {
            fun(ls, l, mid, t[rt].laz);
            fun(rs, mid + 1, r, t[rt].laz);
            t[rt].laz = 0;
        }
    }
    void build(int rt, int l, int r) {
        if (l == r) {
            t[rt].sum = arr[l];
            t[rt].pos = ksm(base, arr[l]);
            t[rt].neg = ksm(ksm(base, arr[l]), mod - 2);
            return;
        }
        build(ls, l, mid), build(rs, mid + 1, r);
        push_up(rt);
    }
    void update(int rt, int l, int r, int p, int q, int k) {
        if (p > r || q < l) return;
        if (p <= l && r <= q) {
            fun(rt, l, r, k);
            return;
        }
        push_down(rt, l, r);
        update(ls, l, mid, p, q, k), update(rs, mid + 1, r, p, q, k);
        push_up(rt);
    }
    Node query(int rt, int l, int r, int p, int q) {
        if (p <= l && r <= q) return t[rt];
        if (q <= mid) return query(ls, l, mid, p, q);
        if (p > mid) return query(rs, mid + 1, r, p, q);
        push_down(rt, l, r);
        Node left = query(ls, l, mid, p, mid), right = query(rs, mid + 1, r, mid + 1, q);
        Node res;
        res.pos = (left.pos + right.pos) % mod;
        res.neg = (left.neg + right.neg) % mod;
        res.sum = (left.sum + right.sum) % mod;
        return res;
    }
} seg;
void solve() {
    int n, q; cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> arr[i], arr[i] *= 2;
    seg.build(1, 1, n);
    while (q--) {
        int op; cin >> op;
        if (op == 1) {
            int l, r, v; cin >> l >> r >> v;
            v *= 2;
            seg.update(1, 1, n, l, r, v);
        } else {
            int l, r; cin >> l >> r;
            Node tem = seg.query(1, 1, n, l, r);
            if (tem.sum % (r - l + 1)) {
                cout << "NO\n";
                continue;
            }
            int avg = tem.sum / (r - l + 1);
            if (tem.neg * ksm(base, 2 * avg) % mod == tem.pos) cout << "YES\n";
            else cout << "NO\n";
        }
    }
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0),cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5812kb

input:

8 4
1 2 3 4 5 6 7 8
2 1 8
1 1 4 4
2 1 6
2 1 8

output:

YES
NO
YES

result:

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

Test #2:

score: -100
Wrong Answer
time: 1289ms
memory: 40732kb

input:

200000 200000
0 0 0 1 1 0 2 1 1 2 0 1 0 0 0 2 1 0 1 2 2 1 2 1 2 0 0 2 1 2 1 0 0 2 0 2 1 1 1 2 0 0 0 0 2 0 1 0 0 2 2 1 1 0 0 2 1 0 2 0 2 1 2 1 0 1 2 1 0 1 2 1 2 1 0 1 2 0 1 0 1 1 0 2 1 2 0 2 2 1 1 2 1 2 2 0 0 1 2 0 0 2 2 0 1 2 2 0 0 1 2 1 2 0 2 0 0 2 0 2 1 0 1 1 1 1 2 1 2 0 1 2 1 0 2 1 0 1 1 2 2 0 1 ...

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
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
...

result:

wrong answer expected YES, found NO [464th token]