QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#499302 | #6435. Paimon Segment Tree | yangbaich | WA | 3ms | 7968kb | C++14 | 3.7kb | 2024-07-31 11:40:39 | 2024-07-31 11:40:39 |
Judging History
answer
#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
using namespace std;
const int MAXN=5e4+5;
const int MAXQ=5e4+5;
const int mod=1e9+7;
int n,c,q,a[MAXN],inl,inr,inx,iny,ans[MAXQ];
struct matrix{
int x;
int y;
int d[4][4];
matrix operator * (const matrix &oth) const {
matrix re;
re.x=x;
re.y=oth.y;
memset(re.d,0,sizeof re.d);
for(int k=0;k<y;k++)
for(int i=0;i<x;i++)
for(int j=0;j<oth.y;j++)
re.d[i][j]=(1ll*re.d[i][j]+1ll*d[i][k]*oth.d[k][j]%mod)%mod;
return re;
}
}ichi,p1,p2;
struct Node{
int l;
int r;
matrix b;//长度,和,平方和,历史平方和
matrix lzy;
}tr[MAXN<<2];
void Update(int u){
tr[u].b.d[0][1]=(tr[u*2].b.d[0][1]+tr[u*2+1].b.d[0][1])%mod;
tr[u].b.d[0][2]=(tr[u*2].b.d[0][2]+tr[u*2+1].b.d[0][2])%mod;
tr[u].b.d[0][3]=((tr[u*2].b.d[0][3])%mod+tr[u*2+1].b.d[0][3])%mod;
}
void Down(int u){
tr[u*2].lzy=tr[u*2].lzy*tr[u].lzy;
tr[u*2+1].lzy=tr[u*2+1].lzy*tr[u].lzy;
tr[u*2].b=tr[u*2].b*tr[u].lzy;
tr[u*2+1].b=tr[u*2+1].b*tr[u].lzy;
tr[u].lzy=ichi;
}
void Build(int u,int l,int r){
tr[u].l=l;
tr[u].r=r;
tr[u].b.x=1;
tr[u].b.y=4;
memset(tr[u].b.d,0,sizeof tr[u].b.d);
tr[u].b.d[0][0]=r-l+1;
tr[u].lzy=ichi;
if(l==r){
tr[u].b.d[0][1]=a[l];
tr[u].b.d[0][2]=tr[u].b.d[0][3]=1ll*a[l]*a[l]%mod;
return;
}
int mid=(l+r)>>1;
Build(u*2,l,mid);
Build(u*2+1,mid+1,r);
Update(u);
}
void Change(int u,int cl,int cr,matrix pro){
if(cl<=tr[u].l && tr[u].r<=cr){
tr[u].b=tr[u].b*pro;
tr[u].lzy=tr[u].lzy*pro;
return;
}
Down(u);
int mid=(tr[u].l+tr[u].r)>>1;
if(cl<=mid) Change(u*2,cl,cr,pro);
if(cr>mid) Change(u*2+1,cl,cr,pro);
Update(u);
}
int Query(int u,int ql,int qr){
// cout<<u<<" "<<ql<<" "<<qr<<" "<<tr[u].l<<" "<<tr[u].r<<" "<<tr[u].b.d[0][3]<<" "<<tr[5].b.d[0][3]<<endl;
if(ql<=tr[u].l && tr[u].r<=qr) return tr[u].b.d[0][3];
Down(u);
int mid=(tr[u].l+tr[u].r)>>1;
int ans=0;
if(ql<=mid) ans=Query(u*2,ql,qr);
if(qr>mid) ans=(ans+Query(u*2+1,ql,qr))%mod;
return ans;
}
struct CHG{
int cl;
int cr;
int cval;
}chg[MAXQ];
struct QRY{
int ql;
int qr;
int qtim;
int qid;
int qbase;
bool operator < (const QRY &oth) const {
return qtim<oth.qtim;
}
}qry[MAXQ*2];
int qcnt;
signed main(){
ichi.x=ichi.y=p1.x=p1.y=p2.x=p2.y=4;
ichi.d[0][0]=1,ichi.d[1][1]=1,ichi.d[2][2]=1,ichi.d[3][3]=1;
scanf("%d%d%d",&n,&c,&q);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=c;i++) scanf("%d%d%d",&chg[i].cl,&chg[i].cr,&chg[i].cval);
Build(1,1,n);
for(int i=1;i<=q;i++){
scanf("%d%d%d%d",&inl,&inr,&inx,&iny);
if(inx) qry[++qcnt]={inl,inr,inx-1,i,-1};
qry[++qcnt]={inl,inr,iny,i,1};
}
sort(qry+1,qry+1+qcnt);
int pt=1;
while(pt<=qcnt && qry[pt].qtim==0){
// cout<<666;
ans[qry[pt].qid]=ans[qry[pt].qid]+qry[pt].qbase*Query(1,qry[pt].ql,qry[pt].qr);
pt++;
}
for(int i=1;i<=c;i++){
int v=chg[i].cval;
p1.d[0][0]=p1.d[1][1]=p1.d[2][2]=p1.d[3][3]=1;
p1.d[0][1]=v;
p1.d[0][2]=1ll*v*v%mod;
p1.d[0][3]=1ll*v*v%mod;
p1.d[1][2]=2*v%mod;
p1.d[1][3]=2*v%mod;
p1.d[2][3]=1;
p2.d[0][0]=p2.d[1][1]=p2.d[2][2]=p2.d[2][3]=p2.d[3][3]=1;
// cout<<"MATRIX\n";
// for(int j=0;j<4;j++){
// for(int k=0;k<4;k++) printf("%d ",p1.d[j][k]);
// printf("\n");
// }
Change(1,chg[i].cl,chg[i].cr,p1);
if(chg[i].cl>1) Change(1,1,chg[i].cl-1,p2);
if(chg[i].cr<n) Change(1,chg[i].cr+1,n,p2);
while(pt<=qcnt && qry[pt].qtim==i){
// cout<<"CHK"<<qry[pt].qid<<" "<< qry[pt].qbase<<" "<<Query(1,qry[pt].ql,qry[pt].qr)<<endl;
ans[qry[pt].qid]=ans[qry[pt].qid]+qry[pt].qbase*Query(1,qry[pt].ql,qry[pt].qr);
pt++;
}
}
for(int i=1;i<=q;i++) printf("%d\n",(ans[i]+mod)%mod);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5828kb
input:
3 1 1 8 1 6 2 3 2 2 2 0 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7968kb
input:
4 3 3 2 3 2 2 1 1 6 1 3 3 1 3 6 2 2 2 3 1 4 1 3 4 4 2 3
output:
180 825 8
result:
ok 3 number(s): "180 825 8"
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 7908kb
input:
100 107 180 -280960553 266308104 -997644864 856103777 592874377 674379235 -946339772 641750362 642418716 -360811715 -555543246 206614021 358239245 349842656 983198973 807518446 -66612455 -980932737 109826132 -109676067 51226145 452115561 -42729559 -950621304 -87009773 714026474 375317493 693260053 -...
output:
400489222 480617351 531108525 254983761 446689548 -530744039 142229431 307405789 39817281 66225912 247029353 46506707 529135498 578008236 201809860 674078444 746060191 171471121 722471473 657196163 861551838 606551808 360903956 401221326 767571915 669762004 163759234 141144218 579174939 276557168 51...
result:
wrong answer 6th numbers differ - expected: '764223236', found: '-530744039'