QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#603569 | #6435. Paimon Segment Tree | bruteforce_ | WA | 1ms | 3800kb | C++20 | 2.8kb | 2024-10-01 17:23:12 | 2024-10-01 17:23:12 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+7,inf=1e18,mod=1e9+7;
struct seg
{
vector<int> val;
vector<int> tag;
bool bz;
seg()
{
val.assign(5,0);
tag.assign(7,0);
bz=0;
}
seg(vector<int> a,vector<int> b,bool c):val(a),tag(b),bz(c){}
void add(vector<int> &b)
{
//modify val
(val[4]+=val[1]*b[3]%mod+val[2]*b[5]%mod+val[3]*b[6]%mod)%=mod;
(val[3]+=val[1]*b[2]%mod+val[2]*b[4]%mod)%=mod;
(val[2]+=val[1]*b[1]%mod)%=mod;
//modify tag
(tag[6]+=b[6])%=mod;
(tag[5]+=tag[4]*b[6]%mod+b[5])%=mod;
(tag[4]+=b[4])%=mod;
(tag[3]+=tag[1]*b[5]+tag[2]*b[6]+b[3])%=mod;
(tag[2]+=tag[1]*b[4]%mod+b[2])%=mod;
(tag[1]+=b[1])%=mod;
bz=1;
}
};
vector<seg> tr;
void update(int u)
{
int ls=u<<1,rs=u<<1|1;
for(int i=1; i<=4; i++)
{
tr[u].val[i]=tr[ls].val[i]+tr[rs].val[i];
}
}
void pushdown(int u)
{
if(!tr[u].bz) return;
tr[u<<1].add(tr[u].tag);
tr[u<<1|1].add(tr[u].tag);
tr[u].bz=0;
tr[u].tag.assign(7,0);
}
vector<int> a;
void build(int u,int st,int ed)
{
if(st==ed)
{
tr[u].val[1]=1;
tr[u].val[2]=a[st];
tr[u].val[3]=a[st]*a[st];
tr[u].val[4]=a[st]*a[st];
return;
}
int mid=st+ed>>1;
build(u<<1,st,mid);
build(u<<1|1,mid+1,ed);
update(u);
}
void modify(int u,int st,int ed,int l,int r,int k)
{
if(l<=st&&ed<=r)
{
int k2=k*k%mod;
vector<int> b={0,k,k2,k2,2*k%mod,2*k%mod,1};
tr[u].add(b);
return;
}
pushdown(u);
int mid=st+ed>>1;
if(mid>=l)
modify(u<<1,st,mid,l,r,k);
if(mid<r)
modify(u<<1|1,mid+1,ed,l,r,k);
update(u);
}
int query(int u,int st,int ed,int l,int r)
{
if(l<=st&&ed<=r)
{
return tr[u].val[4];
}
pushdown(u);
int mid=st+ed>>1;
int res=0;
if(mid>=l)
res=query(u<<1,st,mid,l,r);
if(mid<r)
res+=query(u<<1|1,mid+1,ed,l,r);
res%=mod;
return res;
}
void O_o()
{
int n,m,Q;
cin>>n>>m>>Q;
tr.assign(n<<2,seg());
vector<int> ans(Q,0);
vector p(m+1,vector<array<int,3>>());//l,r,k
vector q(m+1,vector<array<int,4>>());//l,r,id,1 or -1
a.assign(n+1,0);
for(int i=1; i<=n; i++)
cin>>a[i];
for(int i=1; i<=m; i++)
{
int l,r,k;
cin>>l>>r>>k;
if(l>1)
p[i].push_back({1,l-1,0});
if(r<n)
p[i].push_back({r+1,n,0});
p[i].push_back({l,r,k});
}
for(int i=0; i<Q; i++)
{
int l,r,x,y;
cin>>l>>r>>x>>y;
if(x>0)
q[x-1].push_back({l,r,i,-1});
q[y].push_back({l,r,i,1});
}
build(1,1,n);
for(int i=0; i<=m; i++)
{
for(auto [l,r,k]:p[i])
{
modify(1,1,n,l,r,k);
}
for(auto [l,r,id,t]:q[i])
{
(ans[id]+=mod+t*query(1,1,n,l,r))%=mod;
}
}
for(auto x:ans)
cout<<x<<"\n";
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cout<<fixed<<setprecision(12);
int T=1;
// cin>>T;
while(T--)
{
O_o();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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: 3800kb
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: 1ms
memory: 3672kb
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 925607750 117313530 181879228 559885430 483965751 39817281 66225912 917653342 46506707 529135498 666288217 707745840 674078444 581372182 171471121 393095455 327820145 455767792 606551808 360903956 401221326 767571915 175697977 163759234 141144218 414486930 276557168 246...
result:
wrong answer 4th numbers differ - expected: '254983761', found: '925607750'