結果

問題 No.2340 Triple Tree Query (Easy)
ユーザー 沙耶花
提出日時 2023-06-02 23:07:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 410 ms / 5,000 ms
コード長 1,817 bytes
コンパイル時間 4,184 ms
コンパイル使用メモリ 261,948 KB
最終ジャッジ日時 2025-02-13 20:13:23
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
using P = pair<mint,mint> ;

mint op(mint a,mint b){
	return a+b;
}

mint e(){
	return 0;
}

mint mapping(P a,mint b){
	return a.first * b + a.second;
}

P composition(P a,P b){
	return make_pair(b.first * a.first, b.second * a.first + a.second);
}

P id(){
	return make_pair(1,0);
}

vector<int> ps;
vector<int> l0,r0,l1,r1;
vector<vector<int>> E;
vector<int> is;
vector<int> pos;
void dfs(int cv,int pv){
	ps[cv] = pv;
	l0[cv] = is.size();
	l1[cv] = is.size();
	rep(i,E[cv].size()){
		int to = E[cv][i];
		if(to==pv)continue;
		pos[to] = is.size();
		is.push_back(to);
	}
	r0[cv] = is.size();
	rep(i,E[cv].size()){
		int to = E[cv][i];
		if(to==pv)continue;
		dfs(to,cv);
	}
	r1[cv] = is.size();
}

int main(){
	int n,q;
	cin>>n>>q;
	E.resize(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	l0.resize(n);
	l1.resize(n);
	r0.resize(n);
	r1.resize(n);
	ps.resize(n);
	is.push_back(0);
	pos.resize(n);
	pos[0] = 0;
	dfs(0,-1);
	
	vector<mint> x(n);
	rep(i,n){
		int a;
		cin>>a;
		x[pos[i]] = a;
	}
	
	lazy_segtree<mint,op,e,P,mapping,composition,id> seg(x);
	
	rep(_,q){
		int t;
		cin>>t;
		if(t==1){
			int x;
			cin>>x;
			x--;
			cout<<seg.get(pos[x]).val()<<endl;
		}
		if(t==2){
			int v,k,c,d;
			cin>>v>>k>>c>>d;
			v--;
			seg.apply(l0[v],r0[v],make_pair(c,d));
			seg.apply(pos[v],make_pair(c,d));
			if(v!=0)seg.apply(pos[ps[v]],make_pair(c,d));
		}
		if(t==3){
			int v,c,d;
			cin>>v>>c>>d;
			v--;
			seg.apply(l1[v],r1[v],make_pair(c,d));
			seg.apply(pos[v],make_pair(c,d));
		}
	}
		
	
	return 0;
}
0