QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621894 | #7992. 【模板】线段树 | liuyz11 | WA | 2448ms | 52708kb | C++20 | 2.9kb | 2024-10-08 18:01:27 | 2024-10-08 18:01:32 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const int INF = 0x3f3f3f3f;
const int mod = 1 << 20;
const int MAXN = 2e5 + 5;
struct node{
int flag;
ui f[20];
}tree[MAXN * 4], z;
ui pw[25], C[25][25], tag[MAXN * 4];
int a[MAXN];
node merge(node a, node b){
if(a.flag == -1) return b;
if(b.flag == -1) return a;
node res;
rep(i, 0, 19){
res.f[i] = 0;
rep(j, 0, i) res.f[i] += a.f[j] * b.f[i - j];
}
return res;
}
void add(int p, int pl, int pr, ui x){
pw[0] = 1;
rep(i, 1, 19) pw[i] = pw[i - 1] * x;
repd(i, 19, 1){
rep(j, 0, i - 1){
// if(pr - pl + 1 < i) continue;
tree[p].f[i] += tree[p].f[j] * C[pr - pl + 1 - j][i - j] * pw[i - j];
}
}
}
void pushup(int p){
tree[p] = merge(tree[ls(p)], tree[rs(p)]);
}
void pushdown(int p, int pl, int pr){
if(!tag[p]) return;
int mid = (pl + pr) >> 1;
add(ls(p), pl, mid, tag[p]);
add(rs(p), mid + 1, pr, tag[p]);
tag[ls(p)] += tag[p];
tag[rs(p)] += tag[p];
tag[p] = 0;
}
void build(int p, int pl, int pr){
if(pl == pr){
tree[p].f[0] = 1;
tree[p].f[1] = a[pl] - 1;
return;
}
int mid = (pl + pr) >> 1;
build(ls(p), pl, mid);
build(rs(p), mid + 1, pr);
pushup(p);
}
void update(int p, int pl, int pr, int l, int r, ui x){
if(pl > r || pr < l) return;
if(pl >= l && pr <= r){
add(p, pl, pr, x);
tag[p] += x;
return;
}
pushdown(p, pl, pr);
int mid = (pl + pr) >> 1;
update(ls(p), pl, mid, l, r, x);
update(rs(p), mid + 1, pr, l, r, x);
pushup(p);
}
node query(int p, int pl, int pr, int l, int r){
if(pl > r || pr < l) return z;
if(pl >= l && pr <= r) return tree[p];
pushdown(p, pl, pr);
int mid = (pl + pr) >> 1;
return merge(query(ls(p), pl, mid, l, r), query(rs(p), mid + 1, pr, l, r));
}
int main(){
z.flag = -1;
int n, q;
scanf("%d%d", &n, &q);
rep(i, 1, 20){
C[i][0] = C[i][i] = 1;
rep(j, 1, i - 1) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
rep(i, 1, n) scanf("%d", &a[i]);
build(1, 1, n);
while(q--){
int opt, l, r, x;
scanf("%d%d%d", &opt, &l, &r);
if(opt == 1){
scanf("%d", &x);
update(1, 1, n, l, r, x);
}
else{
node res = query(1, 1, n, l, r);
ui ans = 0;
// rep(i, 0, 5) printf("%d ", res.f[i]);
// puts("");
rep(i, 0, 19) ans += res.f[i];
printf("%d\n", ans % mod);
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5944kb
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
Wrong Answer
time: 2448ms
memory: 52708kb
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:
746709 374347 936993 848159 163157 1036097 489785 825837 964243 44899 531251 1009113 1044363 411507 227139 197093 871455 880925 300813 175305 455827 291089 79815 1017259 116967 197 867207 541243 643281 793259 340127 308335 208595 579069 611487 246411 434083 601261 1028155 588787 980757 461327 241377...
result:
wrong answer 2nd lines differ - expected: '564663', found: '374347'