結果

問題 No.2341 Triple Tree Query (Medium)
ユーザー kotatsugamekotatsugame
提出日時 2023-06-02 23:34:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,768 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 87,728 KB
実行使用メモリ 24,148 KB
最終ジャッジ日時 2023-08-28 06:14:56
合計ジャッジ時間 13,585 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,172 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 239 ms
22,168 KB
testcase_08 AC 231 ms
21,176 KB
testcase_09 AC 228 ms
24,148 KB
testcase_10 AC 230 ms
22,592 KB
testcase_11 AC 236 ms
23,484 KB
testcase_12 AC 234 ms
20,788 KB
testcase_13 AC 232 ms
22,040 KB
testcase_14 AC 229 ms
21,564 KB
testcase_15 AC 226 ms
23,480 KB
testcase_16 AC 232 ms
20,172 KB
testcase_17 AC 198 ms
15,600 KB
testcase_18 AC 201 ms
15,404 KB
testcase_19 AC 202 ms
15,548 KB
testcase_20 AC 199 ms
15,508 KB
testcase_21 AC 199 ms
15,516 KB
testcase_22 AC 203 ms
15,604 KB
testcase_23 AC 200 ms
15,576 KB
testcase_24 AC 204 ms
15,524 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
#include<atcoder/modint>
#include<atcoder/lazysegtree>
using namespace std;
using mint=atcoder::modint998244353;
mint op(mint a,mint b){return a;}
mint e(){return mint::raw(0);}
using F=pair<mint,mint>;
mint mp(F f,mint x){return f.first*x+f.second;}
F cmp(F f,F g){return make_pair(f.first*g.first,f.first*g.second+f.second);}
F id(){return make_pair(mint::raw(1),mint::raw(0));}
int N,Q;
vector<int>G[100000];
int ch[100000],pr[100000],depth[100000];
void dfs_init(int u,int p,int d)
{
	pr[u]=p;
	depth[u]=d;
	if(p!=-1)
	{
		for(int i=0;i+1<G[u].size();i++)if(G[u][i]==p)
		{
			swap(G[u][i],G[u][G[u].size()-1]);
			break;
		}
		G[u].pop_back();
	}
	ch[u]=1;
	for(int v:G[u])
	{
		dfs_init(v,u,d+1);
		ch[u]+=ch[v];
	}
}
vector<int>V;
int inv[100000];
int up[100000];
int cL[100000],cR[100000];
int vL[100000],vR[100000];
void dfs(int u,int hld_p)
{
	up[u]=hld_p;
	sort(G[u].begin(),G[u].end(),[](int l,int r){return ch[l]>ch[r];});
	vL[u]=V.size();
	if(!G[u].empty())
	{//heavy-edge
		int v=G[u][0];
		inv[v]=V.size();
		V.push_back(v);
		dfs(G[u][0],hld_p);
	}
	//light-edge
	cL[u]=V.size();
	for(int i=1;i<G[u].size();i++)
	{
		int v=G[u][i];
		inv[v]=V.size();
		V.push_back(v);
	}
	cR[u]=V.size();
	for(int i=1;i<G[u].size();i++)dfs(G[u][i],G[u][i]);
	vR[u]=V.size();
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>Q;
	for(int i=1;i<N;i++)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs_init(0,-1,0);
	inv[0]=0;
	V.push_back(0);
	dfs(0,0);
	vector<mint>init(N);
	for(int i=0;i<N;i++)
	{
		int x;cin>>x;
		init[inv[i]]=mint::raw(x);
	}
	atcoder::lazy_segtree<mint,op,e,F,mp,cmp,id>seg(init);
	for(int i=0;i<Q;i++)
	{
		int op;cin>>op;
		if(op==1)
		{
			int v;cin>>v;v--;
			cout<<seg.get(inv[v]).val()<<"\n";
		}
		else if(op==2)
		{
			int v,k,c,d;
			cin>>v>>k>>c>>d;v--;
			F f=make_pair(mint::raw(c),mint::raw(d));
			seg.set(inv[v],mp(f,seg.get(inv[v])));
			if(pr[v]!=-1)seg.set(inv[pr[v]],mp(f,seg.get(inv[pr[v]])));
			if(!G[v].empty())seg.set(inv[G[v][0]],mp(f,seg.get(inv[G[v][0]])));
			seg.apply(cL[v],cR[v],f);
		}
		else if(op==3)
		{
			int v,c,d;
			cin>>v>>c>>d;v--;
			F f=make_pair(mint::raw(c),mint::raw(d));
			seg.set(inv[v],mp(f,seg.get(inv[v])));
			seg.apply(vL[v],vR[v],f);
		}
		else
		{
			int u,v,c,d;
			cin>>u>>v>>c>>d;u--,v--;
			F f=make_pair(mint::raw(c),mint::raw(d));
			while(up[u]!=up[v])
			{
				if(depth[up[u]]>depth[up[v]])
				{//u -> up[u]
					seg.apply(inv[up[u]],inv[u]+1,f);
					u=pr[up[u]];
				}
				else
				{//v -> up[v]
					seg.apply(inv[up[v]],inv[v]+1,f);
					v=pr[up[v]];
				}
			}
			if(inv[u]<inv[v])seg.apply(inv[u],inv[v]+1,f);
			else seg.apply(inv[v],inv[u]+1,f);
		}
	}
}
0