关于gpt,我们能从中学到什么oi
  • 板块灌水区
  • 楼主LonginusMonkey
  • 当前回复5
  • 已保存回复5
  • 发布时间2022/12/10 23:50
  • 上次更新2023/10/26 23:51:08
查看原帖
关于gpt,我们能从中学到什么oi
326254
LonginusMonkey楼主2022/12/10 23:50

看前半句 我朋友给我介绍了这个ai,我不相信有这么玄学的东西,于是我给他整了一道黑题P4428 [BJOI2018]二进制,然后他给出的代码是:

#include<iostream>
using namespace std;
const int N = 200010;
int n, m;
int a[N];

struct Node{
    int l, r;
    int cnt;
    int pre0, pre1, pre2;
    int suf0, suf1, suf2;
    int lazy;
}tr[N << 2];

void pushup(int u) {
    int lson = u << 1, rson = u << 1 | 1;
    Node& L = tr[lson], &R = tr[rson];

    L.pre0 = L.l == L.r ? (L.cnt % 3 == 0) : L.pre0;
    L.pre1 = L.l == L.r ? (L.cnt % 3 == 1) : L.pre1;
    L.pre2 = L.l == L.r ? (L.cnt % 3 == 2) : L.pre2;

    R.suf0 = R.l == R.r ? (R.cnt % 3 == 0) : R.suf0;
    R.suf1 = R.l == R.r ? (R.cnt % 3 == 1) : R.suf1;
    R.suf2 = R.l == R.r ? (R.cnt % 3 == 2) : R.suf2;

    tr[u].cnt = (L.cnt + R.cnt) % 3;
    tr[u].pre0 = (L.pre0 + (L.pre1 + L.pre2 * 2) % 3 * R.pre0) % 3;
    tr[u].pre1 = (L.pre1 + (L.pre2 * 2 + L.pre0) % 3 * R.pre0 + R.pre1) % 3;
    tr[u].pre2 = (L.pre2 * 2 + (L.pre0 + L.pre1) % 3 * R.pre0 + (R.pre1 + R.pre2 * 2) % 3) % 3;
    tr[u].suf0 = (R.suf0 + (R.suf1 + R.suf2 * 2) % 3 * L.suf0) % 3;
    tr[u].suf1 = (R.suf1 + (R.suf2 * 2 + R.suf0) % 3 * L.suf0 + L.suf1) % 3;
    tr[u].suf2 = (R.suf2 * 2 + (R.suf0 + R.suf1) % 3 * L.suf0 + (L.suf1 + L.suf2 * 2) % 3) % 3;
}

void pushdown(int u) {
    int lson = u << 1, rson = u << 1 | 1;
    Node& L = tr[lson], &R = tr[rson];

    if (tr[u].lazy) {
        L.cnt = (3 - L.cnt) % 3;
        L.pre0 = (3 - L.pre0) % 3;
        L.pre1 = (3 - L.pre1)% 3;
        L.pre2 = (3 - L.pre2) % 3;
        L.suf0 = (3 - L.suf0) % 3;
        L.suf1 = (3 - L.suf1) % 3;
        L.suf2 = (3 - L.suf2) % 3;
        L.lazy ^= 1;

        R.cnt = (3 - R.cnt) % 3;
        R.pre0 = (3 - R.pre0) % 3;
        R.pre1 = (3 - R.pre1) % 3;
        R.pre2 = (3 - R.pre2) % 3;
        R.suf0 = (3 - R.suf0) % 3;
        R.suf1 = (3 - R.suf1) % 3;
        R.suf2 = (3 - R.suf2) % 3;
        R.lazy ^= 1;

        tr[u].lazy = 0;
    }
}

void build(int u, int l, int r) {
    tr[u] = {l, r};
    if (l == r) {
        tr[u].cnt = a[l];
        tr[u].pre0 = a[l] % 3 == 0;
        tr[u].pre1 = a[l] % 3 == 1;
        tr[u].pre2 = a[l] % 3 == 2;
        tr[u].suf0 = a[l] % 3 == 0;
        tr[u].suf1 = a[l] % 3 == 1;
        tr[u].suf2 = a[l] % 3 == 2;
        return;
    }

    int mid = l + r >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);

    pushup(u);
}

void update(int u, int x, int y) {
    if (tr[u].l >= x && tr[u].r <= y) {
        tr[u].cnt = (3 - tr[u].cnt) % 3;
        tr[u].pre0 = (3 - tr[u].pre0) % 3;
        tr[u].pre1 = (3 - tr[u].pre1) % 3;
        tr[u].pre2 = (3 - tr[u].pre2) % 3;
        tr[u].suf0 = (3 - tr[u].suf0) % 3;
        tr[u].suf1 = (3 - tr[u].suf1) % 3;
        tr[u].suf2 = (3 - tr[u].suf2) % 3;
        tr[u].lazy ^= 1;
        return;
    }

    pushdown(u);

    int mid = tr[u].l + tr[u].r >> 1;
    if (x <= mid) update(u << 1, x, y);
    if (y > mid) update(u << 1 | 1, x, y);

    pushup(u);
}

int query(int u, int x, int y) {    if (tr[u].l >= x && tr[u].r <= y) return tr[u].pre0 + tr[u].pre1 + tr[u].pre2;

    pushdown(u);

    int mid = tr[u].l + tr[u].r >> 1, res = 0;
    if (x <= mid) res += query(u << 1, x, y);
    if (y > mid) res += query(u << 1 | 1, x, y);

    pushup(u);

    return res;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    build(1, 1, n);
    scanf("%d", &m);
    while (m--) {
        int t;
        scanf("%d", &t);
        if (t == 1) {
            int x;
            scanf("%d", &x);
            a[x] ^= 1;
            update(1, x, x);
        } else {
            int x, y;
            scanf("%d%d", &x, &y);
            printf("%d\n", query(1, x, y));
        }
    }
    return 0;
}

但是这个代码是错误的,我不确定是否我打的题意有误,求证实

2022/12/10 23:50
加载中...