QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#603541#6435. Paimon Segment Treebruteforce_WA 1ms3936kbC++202.8kb2024-10-01 17:09:282024-10-01 17:09:28

Judging History

你现在查看的是最新测评结果

  • [2024-10-01 17:09:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3936kb
  • [2024-10-01 17:09:28]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+7,inf=1e18,mod=998244353;
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.clear();
}
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);
	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]+=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: 1ms
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: 3516kb

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: 3936kb

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:

319970821
982036098
487729707
219525501
-357570973
93950215
-249329538
553313942
-572079153
717260249
330341960
347738635
-774785086
374974748
564311761
-780257263
37442138
430173578
761210554
206806445
71704735
706997165
-392064086
101111635
649739372
617354057
41524429
-545126621
539100411
-124615...

result:

wrong answer 1st numbers differ - expected: '400489222', found: '319970821'