QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#354499 | #7992. 【模板】线段树 | PorNPtree# | RE | 0ms | 0kb | C++14 | 2.6kb | 2024-03-15 15:18:10 | 2024-03-15 15:18:11 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int lz[1 << 19], C[N][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 < N; ++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: 0
Runtime Error
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