QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#601065 | #6435. Paimon Segment Tree | myloveATRI | WA | 3ms | 86192kb | C++20 | 4.2kb | 2024-09-29 20:45:19 | 2024-09-29 20:45:20 |
Judging History
answer
#include<bits/stdc++.h>
#include<queue>
#include<string.h>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#define int long long
#define ll long long
#define ull unsigned long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nl t[n].l
#define nr t[n].r
#define gcd __gcd
#define itn int
using namespace std;
const int maxn=2e5+50;
const int N=1e5+50;
const int inf=1e18;
const int INF=2e18;
const int mod=1e9+7;
const double eps=1e-12;
#define pop_count __builtin_popcountll
//const ull mask = std::chrono::steady_clock::now().time_since_epoch().count();
struct Matrix
{
int a[5][5];
Matrix()
{
memset(a,0,sizeof(a));
}
Matrix operator*(const Matrix &b) const
{
Matrix res;
rep(i,1,4) res.a[i][i]=1;
for(int i=1; i<=4; i++)
for(int j=i+1; j<=4; j++)
for(int k=i; k<=j; k++)
{
res.a[i][j]=(res.a[i][j]+a[i][k]*b.a[k][j])%mod;
}
return res;
}
};
struct node{
int l,r;
Matrix b,laz;
}t[maxn];
int a[maxn];
struct Q{
int id,l,r,typ,val;
friend bool operator<(Q a,Q b){return a.val<b.val;}
}qy[maxn];
Matrix cg(int v)
{
Matrix res;
res.a[1][1]=res.a[2][2]=res.a[3][3]=res.a[3][4]=res.a[4][4]=1;
res.a[1][2]=v;
res.a[1][3]=res.a[1][4]=v*v%mod;
res.a[2][3]=res.a[2][4]=2*v%mod;
return res;
}
void merge(int n)
{
rep(i,1,1)
{
rep(j,1,4)
{
t[n].b.a[i][j]=(t[n<<1].b.a[i][j]+t[n<<1|1].b.a[i][j])%mod;
}
}
}
void push_down(int n)
{
t[n<<1].b=t[n<<1].b*t[n].laz;
t[n<<1|1].b=t[n<<1|1].b*t[n].laz;
t[n<<1].laz=t[n<<1].laz*t[n].laz;
t[n<<1|1].laz=t[n<<1|1].laz*t[n].laz;
Matrix tmp;
rep(i,1,4)
{
tmp.a[i][i]=1;
}
t[n].laz=tmp;
}
void update(int n,int l,int r,int v)
{
if(l>r) return;
if(nl>=l&&nr<=r)
{
Matrix x=cg(v);
t[n].b=t[n].b*x;
t[n].laz=t[n].laz*x;
return;
}
push_down(n);
int mid=nl+nr>>1;
if(l<=mid) update(n<<1,l,r,v);
if(r>mid) update(n<<1|1,l,r,v);
merge(n);
}
int query(int n,int l,int r)
{
if(nl>=l&&nr<=r) return t[n].b.a[1][4];
int mid=nl+nr>>1;
push_down(n);
int res=0;
if(l<=mid) res+=query(n<<1,l,r);
if(r>mid) res+=query(n<<1|1,l,r);
return res;
}
void build(int n,int l,int r)
{
nl=l,nr=r;
rep(i,1,4) t[n].laz.a[i][i]=1;
if(l==r)
{
t[n].b.a[1][1]=r-l+1;
t[n].b.a[1][2]=a[l];
t[n].b.a[1][3]=t[n].b.a[1][4]=a[l]*a[l]%mod;
return;
}
int mid=nl+nr>>1;
build(n<<1,l,mid);
build(n<<1|1,mid+1,r);
merge(n);
}
int l[maxn],r[maxn],x[maxn];
int ans[maxn];
void solve()
{
int n,m,q;
cin>>n>>m>>q;
rep(i,1,n)
{
cin>>a[i];
if(a[i]<0) a[i]+=mod;
}
build(1,1,n);
rep(i,1,m)
{
cin>>l[i]>>r[i]>>x[i];
if(x[i]<0) x[i]+=mod;
}
int cnt=0;
rep(i,1,q)
{
int u,v,x,y;
cin>>u>>v>>x>>y;
qy[++cnt].l=u;
qy[cnt].r=v;
qy[cnt].val=x-1;
qy[cnt].typ=-1;
qy[cnt].id=i;
qy[++cnt].l=u;
qy[cnt].r=v;
qy[cnt].val=y;
qy[cnt].typ=1;
qy[cnt].id=i;
}
sort(qy+1,qy+1+2*q);
int now=1;
rep(i,0,m)
{
if(i)
{
update(1,l[i],r[i],x[i]);
update(1,1,l[i]-1,0);
update(1,r[i]+1,n,0);
// cout<<n<<'\n';
}
// cout<<query(1,4,4)<<'\n';
while(now<=2*q&&qy[now].val<i)
{
now++;
}
while(now<=2*q&&qy[now].val==i)
{
ans[qy[now].id]+=qy[now].typ*query(1,qy[now].l,qy[now].r);
// cout<<query(1,qy[now].l,qy[now].r);
now++;
}
if(now>2*q) break;
}
rep(i,1,q) cout<<(ans[i]%mod+mod)%mod<<'\n';
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int __=1;
//srand((time(0)));
//cin>>__;
while(__--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 86192kb
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: -100
Wrong Answer
time: 3ms
memory: 86152kb
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 735 8
result:
wrong answer 2nd numbers differ - expected: '825', found: '735'