ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213162 | #584. t3 | fddwd | 20 | 18ms | 66932kb | C++11 | 4.3kb | 2024-11-09 21:58:45 | 2024-11-09 23:24:10 |
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fir first
#define sec second
#define MAXN 100010
const int mod=1e9+7;
int n,m;
ll a[MAXN],C[11][11];
struct nod{
int l,r;ll val[11],lazy=0;set<pll>lazy1;pll lazy2={0,0};
}tree[MAXN<<2];
inline ll power(ll a,ll b){
if(!b||a==1) return 1;
if(b&1) return power(a,b-1)*a%mod;
ll x=power(a,b>>1);return x*x%mod;
}inline void change(int id,ll delta){
ll val[11];memset(val,0,sizeof(val));
for(int i=0;i<=10;++i)for(int j=0;j<=i;++j)
(val[i]+=C[i][j]*power(delta,i-j)%mod*tree[id].val[j])%=mod;
for(int i=0;i<=10;++i) tree[id].val[i]=val[i];
}inline void pushdown(int id){
if(tree[id].l==tree[id].r){tree[id].lazy2={0,0};return;}
int v=id<<1;
if(tree[id].lazy2>tree[v].lazy2){
tree[v].lazy2=tree[id].lazy2;
while(!tree[v].lazy1.empty()&&(*tree[v].lazy1.begin()).fir<tree[v].lazy2.fir)
(tree[v].lazy+=mod-(*tree[v].lazy1.begin()).sec)%=mod,
tree[v].lazy1.erase(tree[v].lazy1.begin());
tree[v].val[0]=tree[v].r-tree[v].l+1;
for(int i=1;i<=10;++i)
tree[v].val[i]=(tree[v].val[i-1]*tree[v].lazy2.sec)%mod;
change(v,tree[v].lazy);
}for(auto it=tree[id].lazy1.begin();it!=tree[id].lazy1.end();++it)
if(!tree[v].lazy1.count(*it)&&(*it).fir>tree[v].lazy2.fir)
tree[v].lazy1.insert(*it),change(v,(*it).sec),
(tree[v].lazy+=(*it).sec)%=mod;
++v;
if(tree[id].lazy2>tree[v].lazy2){
tree[v].lazy2=tree[id].lazy2;
while(!tree[v].lazy1.empty()&&(*tree[v].lazy1.begin()).fir<tree[v].lazy2.fir)
(tree[v].lazy+=mod-(*tree[v].lazy1.begin()).sec)%=mod,
tree[v].lazy1.erase(tree[v].lazy1.begin());
tree[v].val[0]=tree[v].r-tree[v].l+1;
for(int i=1;i<=10;++i)
tree[v].val[i]=(tree[v].val[i-1]*tree[v].lazy2.sec)%mod;
change(v,tree[v].lazy);
}for(auto it=tree[id].lazy1.begin();it!=tree[id].lazy1.end();++it)
if(!tree[v].lazy1.count(*it)&&(*it).fir>tree[v].lazy2.fir)
tree[v].lazy1.insert(*it),change(v,(*it).sec),
(tree[v].lazy+=(*it).sec)%=mod;
}inline void pushup(int id){
if(tree[id].l==tree[id].r) return;
pushdown(id),pushdown(id<<1),pushdown(id<<1|1);
for(int i=0;i<=10;++i)
tree[id].val[i]=(tree[id<<1].val[i]+tree[id<<1|1].val[i])%mod;
}inline void st_build(int id,int l,int r){
tree[id].l=l,tree[id].r=r;
if(l==r){
tree[id].val[0]=1;
for(int i=1;i<=10;++i) tree[id].val[i]=tree[id].val[i-1]*a[l]%mod;
return;
}int mid=(l+r)>>1;
st_build(id<<1,l,mid),st_build(id<<1|1,mid+1,r),pushup(id);
}inline void st_modify1(int id,int l,int r,int s,ll delta){
pushdown(id);
if(l<=tree[id].l&&tree[id].r<=r){
tree[id].lazy1.insert({s,delta}),
change(id,delta),
(tree[id].lazy+=delta)%=mod;
return;
}int mid=(tree[id].l+tree[id].r)>>1;
if(l<=mid) st_modify1(id<<1,l,r,s,delta);
if(mid<r) st_modify1(id<<1|1,l,r,s,delta);
pushup(id);
}inline void st_modify2(int id,int l,int r,int s,ll num){
pushdown(id);
if(l<=tree[id].l&&tree[id].r<=r){
tree[id].lazy2={s,num};
tree[id].val[0]=tree[id].r-tree[id].l+1;
for(int i=1;i<=10;++i) tree[id].val[i]=(tree[id].val[i-1]*num)%mod;
tree[id].lazy1.clear(),tree[id].lazy=0;
return;
}int mid=(tree[id].l+tree[id].r)>>1;
if(l<=mid) st_modify2(id<<1,l,r,s,num);
if(mid<r) st_modify2(id<<1|1,l,r,s,num);
pushup(id);
}inline ll st_query(int id,int l,int r,int p){
pushdown(id);
if(l<=tree[id].l&&tree[id].r<=r) return tree[id].val[p];
int mid=(tree[id].l+tree[id].r)>>1;
ll sum=0;
if(l<=mid) sum+=st_query(id<<1,l,r,p);
if(mid<r) sum+=st_query(id<<1|1,l,r,p);
return sum%mod;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;++i) cin>>a[i];
for(int i=0;i<=10;++i) C[i][0]=1;
for(int i=1;i<=10;++i)for(int j=1;j<=i;++j)
C[i][j]=C[i-1][j]+C[i-1][j-1];
st_build(1,1,n);
short type;int l,r,x;
for(int s=1;s<=m;++s){
cin>>type>>l>>r>>x;
if(n<=1000){
if(type==1) for(int i=l;i<=r;++i) (a[i]+=x)%=mod;
if(type==2) for(int i=l;i<=r;++i) a[i]=x;
if(type==3){
ll ans=0;
for(int i=l;i<=r;++i) (ans+=power(a[i],x))%=mod;
cout<<ans<<endl;
}continue;
}if(type==1) st_modify1(1,l,r,s,x);
if(type==2) st_modify2(1,l,r,s,x);
if(type==3) cout<<st_query(1,l,r,x)<<endl;
}
return 0;
}/*
5 6
1 2 3 4 5
3 1 5 2
3 2 4 3
1 1 1 2
3 1 3 3
2 3 5 4
3 1 4 2
*/
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 4ms
memory: 66928kb
input:
458 823 14431 9895 11970 15308 2575 20181 709 27999 12992 18884 11061 16281 5044 28990 25092 28337 3...
output:
806084096 117884357 581509507 903754571 381316325 789203673 312340523 659242359 741787988 89040104 4...
result:
ok 261 lines
Test #2:
score: 10
Accepted
time: 14ms
memory: 66932kb
input:
481 526 8409 14498 18636 10027 24362 32458 17986 17730 11956 19192 2193 1034 29317 19284 16210 26242...
output:
867105097 717265913 288311190 320452351 133 498037408 473281413 216488030 182572597 611630662 471106...
result:
ok 179 lines
Test #3:
score: 0
Time Limit Exceeded
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 235929450 38218 30045720 19138 459644406 33559 30953524...
result:
Test #4:
score: 0
Time Limit Exceeded
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 159789457 695071461 3136 95363...
result:
Test #5:
score: 0
Time Limit Exceeded
input:
100000 100000 15043 9299 7163 25384 24996 3803 24356 12466 22073 12987 8931 14997 3951 32704 23076 8...
output:
754347097 6296 588341566 325967942 180064833 683 831351544 63953 57030 17635 175222109 5280 57193 32...
result:
Test #6:
score: 0
Time Limit Exceeded
input:
100000 100000 14736 16956 19864 23894 29403 5507 12182 6188 17192 14440 18618 3970 15396 15037 23334...
output:
17008 73008 935797904 16519312 15383 25232 236856418 75334 25854 46510 797344028 517157465 595936107...
result:
Test #7:
score: 0
Time Limit Exceeded
input:
50000 50000 17799 29763 25337 21321 1391 31852 27418 28753 18524 14044 15976 18893 12274 22834 11348...
output:
19498 473297203 695948777 299749756 50630760 692747746 369627246 181903142 328502296 939823794 69850...
result:
Test #8:
score: 0
Time Limit Exceeded
input:
50000 50000 10654 14956 14287 25326 8102 30579 11682 23553 272 22672 14460 30241 13026 12738 4912 72...
output:
717018991 140916081 273712387 602991268 878512570 665908548 10388 4939 283493752 435656498 657720400...
result:
Test #9:
score: 0
Time Limit Exceeded
input:
90000 90000 29538 28214 24706 30393 27759 9002 13458 10243 15713 14881 10630 5593 7942 24578 29370 1...
output:
738835738 738703020 3888 402391875 37270 872563699 273399892 807398793 365897262 255303782 93280847 ...
result:
Test #10:
score: 0
Time Limit Exceeded
input:
100000 100000 23515 49 31372 25112 16779 21279 30735 32743 14678 15189 1763 23114 32215 14873 20487 ...
output:
576735050 562509678 553431297 662173102 515338212 478400370 879269281 500659410 483381164 1679282 16...