結果

問題 No.2340 Triple Tree Query (Easy)
ユーザー kotatsugamekotatsugame
提出日時 2023-06-02 23:21:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 215 ms / 5,000 ms
コード長 1,664 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 84,196 KB
実行使用メモリ 22,968 KB
最終ジャッジ日時 2023-08-28 05:53:33
合計ジャッジ時間 9,470 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,112 KB
testcase_01 AC 6 ms
6,452 KB
testcase_02 AC 6 ms
6,280 KB
testcase_03 AC 5 ms
6,288 KB
testcase_04 AC 6 ms
6,320 KB
testcase_05 AC 6 ms
6,280 KB
testcase_06 AC 184 ms
13,868 KB
testcase_07 AC 183 ms
13,884 KB
testcase_08 AC 183 ms
13,884 KB
testcase_09 AC 183 ms
13,904 KB
testcase_10 AC 182 ms
13,792 KB
testcase_11 AC 181 ms
13,840 KB
testcase_12 AC 183 ms
13,800 KB
testcase_13 AC 181 ms
13,788 KB
testcase_14 AC 180 ms
13,868 KB
testcase_15 AC 181 ms
13,868 KB
testcase_16 AC 215 ms
22,968 KB
testcase_17 AC 209 ms
19,996 KB
testcase_18 AC 210 ms
19,528 KB
testcase_19 AC 210 ms
22,260 KB
testcase_20 AC 210 ms
19,412 KB
testcase_21 AC 158 ms
14,376 KB
testcase_22 AC 156 ms
14,568 KB
testcase_23 AC 157 ms
14,288 KB
testcase_24 AC 207 ms
14,036 KB
testcase_25 AC 204 ms
13,856 KB
testcase_26 AC 204 ms
13,948 KB
testcase_27 AC 208 ms
13,960 KB
testcase_28 AC 203 ms
13,892 KB
testcase_29 AC 155 ms
14,340 KB
testcase_30 AC 153 ms
14,320 KB
testcase_31 AC 154 ms
14,336 KB
testcase_32 AC 185 ms
14,112 KB
testcase_33 AC 187 ms
14,044 KB
testcase_34 AC 189 ms
14,064 KB
testcase_35 AC 186 ms
14,000 KB
testcase_36 AC 188 ms
13,992 KB
権限があれば一括ダウンロードができます

ソースコード

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];
vector<int>V;
int inv[100000],pr[100000];
int cL[100000],cR[100000];
int vL[100000],vR[100000];
void dfs(int u,int p)
{
	pr[u]=p;
	cL[u]=vL[u]=V.size();
	for(int v:G[u])if(v!=p)
	{
		inv[v]=V.size();
		V.push_back(v);
	}
	cR[u]=V.size();
	for(int v:G[u])if(v!=p)dfs(v,u);
	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);
	}
	inv[0]=0;
	V.push_back(0);
	dfs(0,-1);
	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]])));
			seg.apply(cL[v],cR[v],f);
		}
		else
		{
			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);
		}
	}
}
0