QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#352525 | #7992. 【模板】线段树 | zzy0922 | RE | 0ms | 23248kb | C++14 | 3.2kb | 2024-03-13 12:07:24 | 2024-03-13 12:07:24 |
Judging History
answer
#include <bits/stdc++.h>
using uint = unsigned int;
char buf[1 << 20], *p1, *p2;
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++)
inline int read() {
int res = 0;
char c = gc();
while (!isdigit(c)) c = gc();
while (isdigit(c)) res = (res << 1) + (res << 3) + (c ^ 48), c = gc();
return res;
}
constexpr int N = 200005, mod = 1 << 20;
template<class T>
inline int fmod(T x) {
return x & ((1u << 20) - 1u);
}
int n, q;
int a[N];
int C[200005][25];
struct node {
int l, r;
uint v[22], t;
}tree[N << 2];
#define ls(p) (p << 1)
#define rs(p) (ls(p) | 1)
#define l(p) tree[p].l
#define r(p) tree[p].r
#define v(p) tree[p].v
#define t(p) tree[p].t
#define len(p) (r(p) - l(p) + 1)
inline void merge(uint *c, uint *a, uint *b) {
for (int i = 0; i < 20; i++) {
c[i] = 0;
for (int j = 0; j <= i; j++)
c[i] = a[j] * b[i - j] + c[i];
}
}
inline void node_add(int p, uint x) {
// std::cout << "ADD: " << p << ' ' << x << '\n';
// t(p) += x;
static uint pow[22];
pow[0] = 1;
for (int i = 1; i < 20; i++) pow[i] = pow[i - 1] * x;
for (int i = 19; i >= 0; i--) {
for (int j = i - 1; j >= 0; j--) {
v(p)[i] = v(p)[j] * pow[i - j] * C[len(p) - j][i - j] + v(p)[i];
}
}
}
inline void pushdown(int p) {
if (!t(p)) return;
// std::cout << "pushdown "<< p << ' ' << t(p) << '\n';
node_add(p, t(p));
t(ls(p)) += t(p);
t(rs(p)) += t(p);
t(p) = 0;
}
inline void pushup(int p) {
pushdown(ls(p));
pushdown(rs(p));
merge(v(p), v(ls(p)), v(rs(p)));
}
void build(int p, int l, int r) {
// std::cout << p << ' ' << l << ' ' << r << '\n';
l(p) = l, r(p) = r, t(p) = 0;
if (l == r) {
memset(v(p), 0, sizeof(v(p)));
v(p)[0] = 1;
v(p)[1] = a[l] - 1;
return;
}
int mid = (l + r) >> 1;
build(ls(p), l, mid);
build(rs(p), mid + 1, r);
pushup(p);
}
void add(int p, int l, int r, uint x) {
if (l > r(p) || r < l(p)) return;
pushdown(p);
if (l <= l(p) && r(p) <= r) {
// node_add(p, x);
t(p) += x;
// pushdown(p);
return;
}
add(ls(p), l, r, x);
add(rs(p), l, r, x);
pushup(p);
}
uint ans[22];
void qry(int p, int l, int r) {
if (l > r(p) || r < l(p)) return;
pushdown(p);
if (l <= l(p) && r(p) <= r) {
// std::cout << p << '\n';
static uint rans[22];
memcpy(rans, ans, sizeof ans);
merge(ans, rans, v(p));
return;
}
qry(ls(p), l, r);
qry(rs(p), l, r);
}
inline uint Qry(int l, int r) {
memset(ans, 0, sizeof ans);
ans[0] = 1;
qry(1, l, r);
uint res = 0;
for (int i = 0; i < 20; i++) res += ans[i];
return fmod(res);
}
signed main() {
// freopen("in.in", "r", stdin);
std::cin.tie(0)->sync_with_stdio(0);
for (int i = 0; i <= 200000; i++) {
C[i][0] = 1;
for (int j = 1; j <= 20; j++)
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
n = read(), q = read();
for (int i = 1; i <= n; i++) a[i] = read();
build(1, 1, n);
int op, l, r, x;
while (q--) {
op = read(), l = read(), r = read();
if (op == 1) {
x = read();
add(1, l, r, x);
} else {
std::cout << Qry(l, r) << '\n';
// for (int i = 0; i < 20; i++) std::cout << v(11)[i] << ' ';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 23248kb
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...