P7077,CSP2020提高,T3,线段树暴力,求大佬指点
查看原帖
P7077,CSP2020提高,T3,线段树暴力,求大佬指点
117841
WDySrDbMoAuMc楼主2020/11/7 23:08
#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
inline void read(int &x) {
	x = 0;
	register char c = getchar();
	while(c > '9' || c < '0')
		c = getchar();
	do {
		x = (x << 3) + (x << 1) + (c ^ 48);
		c = getchar();
	} while(c >= '0' && c <= '9');
}
struct node {
	int T,p,v,c;
	vector<int> g;
} f[100005];
struct tree {
	int l,r;
	long long lazy;
} a[400005];
int n,m,q,_g,_f,x,y,k,arr[100005];
void build(int p,int l,int r) {
	a[p].l = l;
	a[p].r = r;
	a[p].lazy = 1;
	if(l == r) {
		a[p].lazy = arr[l];
		return;
	}
	int mid = l + r >> 1;
	build(p << 1,l,mid);
	build(p << 1 | 1,mid + 1,r);
}
inline void push_down(int p) {
	if(a[p].lazy != 1 && a[p].l != a[p].r) {
		a[p << 1].lazy = a[p << 1].lazy * a[p].lazy % mod;
		a[p << 1 | 1].lazy = a[p << 1 | 1].lazy * a[p].lazy % mod;
		a[p].lazy = 1;
	}
}
inline void update1(int p) {
	a[p].lazy = a[p].lazy * k % mod;
}
void update2(int p,int x) {
	if(x == a[p].l && x == a[p].r) {
		a[p].lazy = (a[p].lazy + k) % mod;
		return;
	}
	push_down(p);
	int mid = a[p].l + a[p].r >> 1;
	if(x <= mid)
		update2(p << 1,x);
	else
		update2(p << 1 | 1,x);
}
long long que(int p,int x) {
	if(x == a[p].l && x == a[p].r)
		return a[p].lazy;
	push_down(p);
	int mid = a[p].r + a[p].l >> 1;
	if(x <= mid)
		return que(p << 1,x);
	return que(p << 1 | 1,x);
}
void dfs(int x) {
	for(register int i = 0; i < f[x].c; ++i) {
		if(f[f[x].g[i]].T == 3)
			dfs(f[x].g[i]);
		else {
			k = f[f[x].g[i]].v;
			if(f[f[x].g[i]].T == 2)
				update1(1);
			else update2(1,f[f[x].g[i]].p);
		}
	}
}
int main() {
	cin >> n;
	for(int i = 1; i <= n; ++i)
		read(arr[i]);
	build(1,1,n);
	cin >> m;
	for(int i = 1; i <= m; ++i) {
		read(f[i].T);
		if(f[i].T == 1) {
			read(f[i].p);
			read(f[i].v);
		} else if(f[i].T == 2) {
			read(f[i].v);
		} else {
			read(f[i].c);
			for(int j = 1; j <= f[i].c; ++j) {
				read(_g);
				f[i].g.push_back(_g);
			}
		}
	}
	cin >> q;
	for(int i = 1; i <= q; ++i) {
		read(_f);
		if(f[_f].T == 3)
			dfs(_f);
		else {
			k = f[_f].v;
			if(f[_f].T == 2)
				update1(1);
			else update2(1,f[_f].p);
		}
	}
	for(int i = 1; i <= n; ++i)
		printf("%d ",que(1,i));
	return 0;
}
2020/11/7 23:08
加载中...