QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#694361 | #6435. Paimon Segment Tree | zth# | WA | 103ms | 182024kb | C++23 | 3.7kb | 2024-10-31 17:46:54 | 2024-10-31 17:46:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const ll mod=1e9+7;
const int MX=50000;
struct mat {
vector<vector<ll>> a;
mat(){}
mat(ll w) {
if (w!=-1) a={{1,1,2*w%mod,w*w%mod}, {0,1,2*w%mod,w*w%mod}, {0,0,1,w}, {0,0,0,1}};
else a={{-1,-1,-1,-1}, {-1,-1,-1,-1}, {-1,-1,-1,-1}, {-1,-1,-1,-1}};
}
} lz[10*MX+20];
mat mul_mat(mat &A, mat &B) {
if (A.a[0][0]==-1) return B;
if (B.a[0][0]==-1) return A;
mat res=mat(0);
for (int i=0; i<4; ++i) {
for (int j=0; j<4; ++j) {
res.a[i][j]=0;
for (int k=0; k<4; ++k) res.a[i][j]=(res.a[i][j]+A.a[i][k]*B.a[k][j])%mod;
}
}
return res;
}
struct vec {
ll sum_sq,sq,sum,cnt;
vec() : sum_sq(0), sq(0), sum(0), cnt(0) {}
vec(ll val) : sum_sq(val*val%mod), sq(val*val%mod), sum(val), cnt(1) {}
vec(vec A, vec B) {
sum_sq=(A.sum_sq+B.sum_sq)%mod;
sq=(A.sq+B.sq)%mod;
sum=(A.sum+B.sum)%mod;
cnt=A.cnt+B.cnt;
}
} s[10*MX+20];
vec mul_vec(vec &A, mat &B) {
if (B.a[0][0]==-1) return A;
vec res=vec(0);
res.sum_sq = (B.a[0][0]*A.sum_sq + B.a[0][1]*A.sq + B.a[0][2]*A.sum + B.a[0][3]*A.cnt)%mod;
res.sq = (B.a[1][0]*A.sum_sq + B.a[1][1]*A.sq + B.a[1][2]*A.sum + B.a[1][3]*A.cnt)%mod;
res.sum = (B.a[2][0]*A.sum_sq + B.a[2][1]*A.sq + B.a[2][2]*A.sum + B.a[2][3]*A.cnt)%mod;
res.cnt = (B.a[3][0]*A.sum_sq + B.a[3][1]*A.sq + B.a[3][2]*A.sum + B.a[3][3]*A.cnt)%mod;
return res;
}
void pushlz(int l, int r, int idx) {
s[idx]=mul_vec(s[idx],lz[idx]);
if (l!=r) {
lz[2*idx]=mul_mat(lz[idx],lz[2*idx]);
lz[2*idx+1]=mul_mat(lz[idx],lz[2*idx+1]);
}
lz[idx]=mat(-1);
}
void update(int l, int r, int idx, int x, int y, ll val) {
pushlz(l,r,idx);
if (x>r || y<l) return;
if (x<=l && r<=y) {
lz[idx]=mat(val);
pushlz(l,r,idx);
} else {
int mid=(l+r)/2;
update(l,mid,2*idx,x,y,val);
update(mid+1,r,2*idx+1,x,y,val);
s[idx]=vec(s[2*idx],s[2*idx+1]);
}
}
vec query(int l, int r, int idx, int x, int y) {
pushlz(l,r,idx);
if (x>r || y<l) return vec();
if (x<=l && r<=y) return s[idx];
int mid=(l+r)/2;
return vec(query(l,mid,2*idx,x,y),query(mid+1,r,2*idx+1,x,y));
}
int n,m,q;
ll c[MX+5],ans[MX+5];
void build(int l, int r, int idx) {
if (l==r) s[idx]=vec(c[l]);
else {
int mid=(l+r)/2;
build(l,mid,2*idx);
build(mid+1,r,2*idx+1);
s[idx]=vec(s[2*idx],s[2*idx+1]);
}
}
struct tup {
ll a,b,c; //idx of ans, l, r
};
vector<tup> op,del[MX+5],add[MX+5];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
for (int i=0; i<=10*MX+3; ++i) lz[i]=mat(-1);
cin>>n>>m>>q;
for (int i=1; i<=n; ++i) cin>>c[i];
build(1,n,1);
op.push_back({0,0,0});
for (int i=1; i<=m; ++i) {
int l,r,x; cin>>l>>r>>x;
op.push_back({l,r,x});
}
for (int i=1; i<=q; ++i) {
int l,r,x,y; cin>>l>>r>>x>>y;
add[y].push_back({i,l,r});
if (x) del[x-1].push_back({i,l,r});
}
for (int i=0; i<=m; ++i) {
ll l=op[i].a, r=op[i].b, w=op[i].c;
if (i) {
update(1,n,1,l,r,w);
if (l!=1) update(1,n,1,1,l-1,0);
if (r!=n) update(1,n,1,r+1,n,0);
}
for (auto s : add[i]) ans[s.a]=(ans[s.a]+query(1,n,1,s.b,s.c).sum_sq)%mod;
for (auto s : del[i]) ans[s.a]=((ans[s.a]-query(1,n,1,s.b,s.c).sum_sq)%mod+mod)%mod;
}
for (int i=1; i<=q; ++i) cout<<ans[i]<<"\n";
}
/*
3 1 1
8 1 6
2 3 2
2 2 0 0
*/
详细
Test #1:
score: 100
Accepted
time: 97ms
memory: 180092kb
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: 88ms
memory: 180720kb
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: 103ms
memory: 182024kb
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 764223236 142229431 307405789 39817281 66225912 247029353 46506707 -470864509 578008236 -798190147 674078444 746060191 171471121 722471473 657196163 -138448169 606551808 -639096051 401221326 767571915 669762004 163759234 141144218 579174939 276557168...
result:
wrong answer 13th numbers differ - expected: '529135498', found: '-470864509'