ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213085 | #584. t3 | wanghanyu393 | 0 | 17100ms | 40960kb | C++ | 4.1kb | 2024-11-09 19:28:03 | 2024-11-09 23:07:43 |
answer
#pragma GCC optimize(2)
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
const int N = 1e5 + 5, mod = 1e9 + 7;
int fast_power(int a, int b){
int ans = 1;
while(b){
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
int c[20][20];
void init(){
c[0][0] = 1;
c[1][0] = 1;
c[1][1] = 1;
for(int i = 2; i <= 15; i++){
c[i][0] = 1;
for(int j = 1; j <= i; j++){
c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
c[i][j] %= mod;
}
}
}
int a[N];
struct node{
int l, r;
int tag1, tag2;
int sum[15];
}tree[N << 2];
void pushup(int k){
int lc = k * 2;
int rc = k * 2 + 1;
for(int i = 0; i <= 10; i++){
tree[k].sum[i] = tree[lc].sum[i] + tree[rc].sum[i];
}
}
void mod_add(int k, int v){
tree[k].tag1 += v;
//int len = (tree[k].r - tree[k].l + 1);
for(int i = 10; i >= 1; i--){
for(int j = i; j >= 1; j--){
tree[k].sum[i] += tree[k].sum[i - j] * c[i][j] * fast_power(v, j);
tree[k].sum[i] %= mod;
}
}
}
void mod_all(int k, int v){
tree[k].tag1 = 0;
tree[k].tag2 = v;
for(int i = 0; i <= 10; i++){
tree[k].sum[i] = fast_power(v, i) * (tree[k].r - tree[k].l + 1) % mod;
}
}
void pushdown(int k){
int lc = k * 2;
int rc = k * 2 + 1;
if(tree[k].tag2){
mod_all(lc, tree[k].tag2);
mod_all(rc, tree[k].tag2);
tree[k].tag2 = 0;
}
if(tree[k].tag1){
mod_add(lc, tree[k].tag1);
mod_add(rc, tree[k].tag1);
tree[k].tag1 = 0;
}
}
void build(int k, int l, int r){
tree[k].l = l, tree[k].r = r;
if(l == r){
for(int i = 0; i <= 10; i++){
tree[k].sum[i] = fast_power(a[l], i);
}
return;
}
int mid = (l + r) >> 1;
int lc = k * 2;
int rc = k * 2 + 1;
build(lc, l, mid);
build(rc, mid + 1, r);
pushup(k);
}
void modify_add(int k, int l, int r, int v){
if(tree[k].l >= l && tree[k].r <= r){
mod_add(k, v);
return;
}
pushdown(k);
int mid = (tree[k].l + tree[k].r) >> 1;
int lc = k * 2;
int rc = k * 2 + 1;
if(r <= mid) modify_add(lc, l, r, v);
else if(l > mid) modify_add(rc, l, r, v);
else modify_add(lc, l, mid, v), modify_add(rc, mid + 1, r, v);
pushup(k);
}
void modify_all(int k, int l, int r, int v){
if(tree[k].r <= r && tree[k].l >= l){
mod_all(k, v);
return;
}
pushdown(k);
int mid = (tree[k].l + tree[k].r) >> 1;
int lc = k * 2;
int rc = k * 2 + 1;
if(r <= mid) modify_all(lc, l, r, v);
else if(l > mid) modify_all(rc, l, r, v);
else modify_all(lc, l, mid, v), modify_all(rc, mid + 1, r, v);
pushup(k);
}
int query(int k, int l, int r, int x){
if(tree[k].l >= l && tree[k].r <= r) return tree[k].sum[x];
pushdown(k);
int mid = (tree[k].l + tree[k].r) >> 1;
int lc = k * 2;
int rc = k * 2 + 1;
if(r <= mid) return query(lc, l, r, x);
else if(l > mid) return query(rc, l, r, x);
else return (query(lc, l, mid, x) + query(rc, mid + 1, r, x) % mod);
}
void print(int k){
if(tree[k].l == 0) return;
int lc = k * 2;
int rc = k * 2 + 1;
cout << tree[k].l << ' ' << tree[k].r << '\n';
for(int i = 1; i <= 10; i++) cout << tree[k].sum << ' ';
}
void solve(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
init();
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
build(1, 1, n);
for(int i = 1; i <= m; i++){
int op, l, r, x;
cin >> op >> l >> r >> x;
if(op == 1){
modify_add(1, l, r, x);
}else if(op == 2){
modify_all(1, l, r, x);
}else{
cout << query(1, l, r, x) << '\n';
}
}
}
signed main(){
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 1424kb
input:
458 823 14431 9895 11970 15308 2575 20181 709 27999 12992 18884 11061 16281 5044 28990 25092 28337 3...
output:
1806084103 2581212959 1581509514 2903754585 2381316339 1789203680 3218884253 3377354174 2741788002 2...
result:
wrong answer 1st lines differ - expected: '806084096', found: '1806084103'
Test #2:
score: 0
Wrong Answer
time: 4ms
memory: 1420kb
input:
481 526 8409 14498 18636 10027 24362 32458 17986 17730 11956 19192 2193 1034 29317 19284 16210 26242...
output:
2867105111 3717265934 3288311211 3320452372 133 2433501347 2863460027 2216488044 1788660518 36116306...
result:
wrong answer 1st lines differ - expected: '867105097', found: '2867105111'
Test #3:
score: 0
Wrong Answer
time: 2884ms
memory: 40956kb
input:
100000 100000 15247 4194 9619 4532 22058 2667 21549 16652 25327 12018 13395 11426 7243 11714 22904 2...
output:
54433 544457741 352487648 82525935 532381851 1235929457 38218 30045720 19138 459644406 33559 1030953...
result:
wrong answer 6th lines differ - expected: '235929450', found: '1235929457'
Test #4:
score: 0
Wrong Answer
time: 2384ms
memory: 40960kb
input:
100000 100000 6264 26207 28424 24165 4852 20798 5803 18679 24588 12238 25786 28622 19900 101 25922 2...
output:
18923 13111195 41716 34447 32091 80654 731180277 9973 523560023 19797 1159789464 695071461 3136 9536...
result:
wrong answer 11th lines differ - expected: '159789457', found: '1159789464'
Test #5:
score: 0
Wrong Answer
time: 2413ms
memory: 40956kb
input:
100000 100000 15043 9299 7163 25384 24996 3803 24356 12466 22073 12987 8931 14997 3951 32704 23076 8...
output:
2754347111 6296 588341566 5325967977 180064833 683 2831351558 63953 57030 17635 2175222123 5280 5719...
result:
wrong answer 1st lines differ - expected: '754347097', found: '2754347111'
Test #6:
score: 0
Wrong Answer
time: 2381ms
memory: 40960kb
input:
100000 100000 14736 16956 19864 23894 29403 5507 12182 6188 17192 14440 18618 3970 15396 15037 23334...
output:
17008 73008 935797904 1016519319 15383 25232 8236856474 75334 25854 46510 797344028 517157465 259593...
result:
wrong answer 4th lines differ - expected: '16519312', found: '1016519319'
Test #7:
score: 0
Wrong Answer
time: 1071ms
memory: 21116kb
input:
50000 50000 17799 29763 25337 21321 1391 31852 27418 28753 18524 14044 15976 18893 12274 22834 11348...
output:
19498 2473297217 5695948812 1859588396 2050630774 4830518537 3369627267 2635249002 6328502338 515622...
result:
wrong answer 2nd lines differ - expected: '473297203', found: '2473297217'
Test #8:
score: 0
Wrong Answer
time: 1013ms
memory: 21116kb
input:
50000 50000 10654 14956 14287 25326 8102 30579 11682 23553 272 22672 14460 30241 13026 12738 4912 72...
output:
1717018998 140916081 2668632118 1537214654 1978664511 5424812546 10388 4939 4283493780 4941592506 65...
result:
wrong answer 1st lines differ - expected: '717018991', found: '1717018998'
Test #9:
score: 0
Wrong Answer
time: 2546ms
memory: 40884kb
input:
90000 90000 29538 28214 24706 30393 27759 9002 13458 10243 15713 14881 10630 5593 7942 24578 29370 1...
output:
14738835836 738703020 3888 402391875 37270 1872563706 1273399899 1807398800 4365897290 4176491738 93...
result:
wrong answer 1st lines differ - expected: '738835738', found: '14738835836'
Test #10:
score: 0
Wrong Answer
time: 2396ms
memory: 40956kb
input:
100000 100000 23515 49 31372 25112 16779 21279 30735 32743 14678 15189 1763 23114 32215 14873 20487 ...
output:
5576735085 4562509706 6553431339 2662173116 4348894324 5478400405 2879269295 3684402491 4389558496 4...
result:
wrong answer 1st lines differ - expected: '576735050', found: '5576735085'