QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#610954 | #6435. Paimon Segment Tree | ucup-team4352# | WA | 3ms | 7764kb | C++23 | 3.2kb | 2024-10-04 18:14:30 | 2024-10-04 18:14:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=5e4+5;
int n,m,q,c[maxn];
int l,r,x,y;
struct Data{
int l,r,x,id;
}a[maxn],Q[maxn<<1];
int cnt;
bool comp(Data A,Data B) {
return A.x<B.x;
}
int tr[maxn<<2][4],tmp[4][4],now[4][4];
int lazy[maxn<<2][4][4];
int ans[maxn];
void add(int &x,int y) {
x+=y;
if(x>=mod) x-=mod;
}
void pushup(int rt) {
for(int i=0;i<4;++i) {
tr[rt][i]=tr[rt<<1][i]+tr[rt<<1|1][i];
if(tr[rt][i]>=mod) tr[rt][i]-=mod;
}
}
void build(int rt,int l,int r) {
memcpy(lazy[rt],tmp,sizeof(tmp));
if(l==r) {
tr[rt][0]=1;
tr[rt][1]=c[l];
tr[rt][2]=tr[rt][3]=(ll)c[l]*c[l]%mod;
return;
}
int mid=l+r>>1;
build(rt<<1,l,mid);
build(rt<<1|1,mid+1,r);
pushup(rt);
}
int kp1[4][4],kp2[4];
void qp1(int a[4][4],int b[4][4]) {
for(int i=0;i<4;++i)
for(int j=0;j<4;++j)
for(int k=0;k<4;++k)
add(kp1[i][j],(ll)a[i][k]*b[k][j]%mod);
}
void qp2(int a[4],int b[4][4]) {
for(int j=0;j<4;++j)
for(int k=0;k<4;++k) add(kp2[j],(ll)a[k]*b[k][j]%mod);
}
void pushdown(int rt) {
qp1(lazy[rt<<1],lazy[rt]),qp2(tr[rt<<1],lazy[rt]);
memcpy(lazy[rt<<1],kp1,sizeof(kp1)),memset(kp1,0,sizeof(kp1));
memcpy(tr[rt<<1],kp2,sizeof(kp2)),memset(kp2,0,sizeof(kp2));
qp1(lazy[rt<<1|1],lazy[rt]),qp2(tr[rt<<1|1],lazy[rt]);
memcpy(lazy[rt<<1|1],kp1,sizeof(kp1)),memset(kp1,0,sizeof(kp1));
memcpy(tr[rt<<1|1],kp2,sizeof(kp2)),memset(kp2,0,sizeof(kp2));
memcpy(lazy[rt],tmp,sizeof(tmp));
}
void update(int rt,int l,int r,int L,int R) {
if(L<=l&&R>=r) {
qp1(lazy[rt],now),memcpy(lazy[rt],kp1,sizeof(kp1)),memset(kp1,0,sizeof(kp1));
qp2(tr[rt],now),memcpy(tr[rt],kp2,sizeof(kp2)),memset(kp2,0,sizeof(kp2));
return;
}
int mid=l+r>>1;
pushdown(rt);
if(L<=mid) update(rt<<1,l,mid,L,R);
if(R>mid) update(rt<<1|1,mid+1,r,L,R);
pushup(rt);
}
int query(int rt,int l,int r,int L,int R) {
if(L<=l&&R>=r) return tr[rt][3];
int mid=l+r>>1,res=0;
pushdown(rt);
if(L<=mid) add(res,query(rt<<1,l,mid,L,R));
if(R>mid) add(res,query(rt<<1|1,mid+1,r,L,R));
pushup(rt);
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m>>q;
for(int i=1;i<=n;++i) {
cin>>c[i];
if(c[i]<0) c[i]=mod-c[i];
}
for(int i=1;i<=m;++i) {
cin>>a[i].l>>a[i].r>>a[i].x;
if(a[i].x<0) a[i].x=mod-a[i].x;
}
for(int i=1;i<=q;++i) {
cin>>l>>r>>x>>y;
Q[++cnt]=(Data){l,r,x-1,-i};
Q[++cnt]=(Data){l,r,y,i};
}
sort(Q+1,Q+1+cnt,comp);
int p=1;
for(int i=0;i<4;++i)
for(int j=0;j<4;++j) if(i==j) tmp[i][j]=now[i][j]=1;
build(1,1,n);
for(int i=1;i<=cnt;++i) {
if(Q[i].x==-1) continue;
while(p<=Q[i].x) {
int x=a[p].x;
now[2][3]=1;
now[0][1]=x;
now[1][2]=now[1][3]=(ll)x*2%mod;
now[0][2]=now[0][3]=(ll)x*x%mod;
update(1,1,n,a[p].l,a[p].r);
memcpy(now,tmp,sizeof(tmp));
now[2][3]=1;
if(a[p].l>1) update(1,1,n,1,a[p].l-1);
if(a[p].r<n) update(1,1,n,a[p].r+1,n);
p++;
}
int x=query(1,1,n,Q[i].l,Q[i].r);
if(Q[i].id<0) add(ans[-Q[i].id],mod-x);
else add(ans[Q[i].id],x);
}
for(int i=1;i<=q;++i) cout<<ans[i]<<'\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5620kb
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: 0ms
memory: 7724kb
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: 7764kb
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:
830400381 483055440 870000689 369239733 418297294 86748298 769512077 851315082 850561768 793406452 101684434 215160298 181451829 680273869 713663735 797120218 789483057 358608078 645728721 454395143 118764002 615652995 832130388 96191472 295024255 461904158 216489292 990693559 618273550 108993444 23...
result:
wrong answer 1st numbers differ - expected: '400489222', found: '830400381'