QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354498#7992. 【模板】线段树PorNPtree#RE 0ms44708kbC++142.6kb2024-03-15 15:17:232024-03-15 15:17:24

Judging History

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

  • [2024-03-15 15:17:24]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:44708kb
  • [2024-03-15 15:17:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int lz[1 << 19], C[25][25];

struct op
{
    int z[20];
} t[1 << 19];

op operator + (op x, op y)
{
    op z;
    for (int i = 0; i < 20; ++i) {
        z.z[i] = 0;
        for (int j = 0; j <= i; ++j) {
            z.z[i] = (z.z[i] + 1ll * x.z[j] * y.z[i - j]) & 1048575;
        }
    }
    return z;
}

void addTag(int k, int v, int len)
{
    lz[k] += v;
    lz[k] &= 1048575;
    op z;
    for (int i = 0; i < 20; ++i) {
        z.z[i] = 0;
        for (int j = 0, now = 1; j <= i; ++j, now = 1ll * now * v & 1048575) {
            if (i - j <= len) z.z[i] = (z.z[i] + ((1ll * now * t[k].z[i - j]) & 1048575) * C[len - (i - j)][j]) & 1048575;
        }
    }
    t[k] = z;
    return;
}

void pushdown(int k, int l, int r)
{
    if (lz[k]) {
        int mid = (l + r) >> 1;
        addTag(k << 1, lz[k], mid - l + 1);
        addTag(k << 1 | 1, lz[k], r - mid);
        lz[k] = 0;
    }
    return;
}

void modify(int k, int l, int r, int x, int y, int v)
{
    if (l > y || r < x) {
        return;
    }
    if (l >= x && r <= y) {
        addTag(k, v, r - l + 1);
        return;
    }
    int mid = (l + r) >> 1;
    pushdown(k, l, r);
    modify(k << 1, l, mid, x, y, v);
    modify(k << 1 | 1, mid + 1, r, x, y, v);
    t[k] = t[k << 1] + t[k << 1 | 1];
    return;
}

op query(int k, int l, int r, int x, int y)
{
    if (l >= x && r <= y) {
        return t[k];
    }
    pushdown(k, l, r);
    int mid = (l + r) >> 1;
    if (mid >= y) {
        return query(k << 1, l, mid, x, y);
    }
    if (mid < x) {
        return query(k << 1 | 1, mid + 1, r, x, y);
    }
    return query(k << 1, l, mid, x, y) + query(k << 1 | 1, mid + 1, r, x, y);
}

signed main()
{
    C[0][0] = 1;
    for (int i = 1; i <= 20; ++i) {
        C[i][0] = 1;
        for (int j = 1; j <= i; ++j) {
            C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
        }
    }
    int n, q;
    scanf("%d%d", &n, &q);
    for (int i = 1; i < 1 << 19; ++i) {
        t[i].z[0] = 1;
    }
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x);
        modify(1, 1, n, i, i, x - 1);
    }
    while (q--) {
        int opt, l, r, x;
        scanf("%d%d%d", &opt, &l, &r);
        if (opt == 1) {
            scanf("%d", &x);
            modify(1, 1, n, l, r, x);
        } else {
            op res = query(1, 1, n, l, r);
            int A = 0;
            for (int i = 0; i < 20; ++i) {
                A += res.z[i];
            }
            printf("%d\n", A & 1048575);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

10 10
969575 741825 24903 1047319 450475 256145 1045323 479255 810659 768323
1 5 6 3034
2 1 10
2 1 9
2 1 4
1 3 6 126904
2 5 5
2 9 9
1 7 7 853094
1 4 9 1025178
2 5 8

output:

1045541
1012343
558151
580413
810659
527353

result:

ok 6 lines

Test #2:

score: -100
Runtime Error

input:

200000 200000
496015 180543 330721 874799 740427 144379 598057 795949 323465 87657 683935 748203 748665 288301 846003 33033 746029 132621 876629 361899 701297 373189 256151 723161 377571 54947 91151 855991 433965 73347 155081 314317 790527 705555 1035217 298963 604641 203865 230029 802437 720769 843...

output:


result: