답안 #891666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891666 2023-12-23T14:00:42 Z thunopro Sprinkler (JOI22_sprinkler) C++14
12 / 100
668 ms 205708 KB
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 400009 
#define ll long long 
#define fi first 
#define se second 
#define pb push_back 
#define left id<<1 
#define right id<<1|1
#define re exit(0);
#define _lower(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
 
int mod = 1e9+7 ; 
const int INF = 1e9 ;
const int LOG = 18 ; 
 
typedef vector<int> vi ; 
typedef pair<int,int> pii ; 
typedef vector<pii> vii ;
typedef vector<ll> vl ;  
typedef pair<ll,ll> pll ; 
typedef vector<pll> vll ; 
 
void add ( int&a , int b ) { if ((a+=b) > mod ) a -= mod ; } 
void sub ( int&a , int b ) { if ((a-=b) < 0 ) a += mod ; } 
template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}
 
void rf ( ) 
{
	freopen ("bai1.inp","r",stdin) ; 
//	freopen ("bai1.out","w",stdout) ;
}
 
int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ; 
	int res = _pow ( a , n / 2 ) ; 
	if ( n % 2 ) return ( 1ll * res * res % mod * a % mod ) ; 
	else return ( 1ll * res * res % mod ) ; 
}
 
int n ;
 
vi adjList [maxn] ;
int a [maxn] ; 
 
int nq ; 
struct shape {
	int op , x , d , w ; 
} q [maxn] ; 
 
bool vis [maxn] ; 
void update_near ( int u , int d , int w , int par = -1 ) 
{
	a [u] = 1ll*a[u]*w%mod ; 
	if ( d == 0 ) return ; 
	for ( auto v : adjList [u] ) 
	{
		if ( v != par ) update_near (v,d-1,w,u) ; 
	}
}
void sub1 () 
{
	for ( int rn = 1 ; rn <= nq ; rn ++ ) 
	{
		if ( q[rn].op == 1 ) 
		{
			int x = q [rn].x , d = q [rn].d , w = q [rn].w ; 
			update_near (x,d,w) ; 
		}
		else cout << a [q[rn].x] << "\n" ;  
	}
}
 
bool check_sub2 () 
{
	for ( int i = 1 ; i <= nq ; i ++ ) 
	{
		if ( q [i].op == 1 && q [i].d >= 2 ) return false ; 
	}
	return true ; 
}
 
 
vi vertex_special ; 
int speical [maxn] ;
int lazy_val [maxn] ; 
 
void sub2 () 
{
	map <int,bool> adj [n+5] ; 
	for ( int i = 1 ; i <= n ; i ++ ) lazy_val [i] = 1 ; 
	for ( int i = 1 ; i <= n ; i ++ ) 
	{
		if ( adjList [i].size () > 400 ) speical [i] = true , vertex_special . pb (i) ; 
		for ( auto x : adjList [i] ) adj [x][i] = adj [i][x] = true ; 
	}
	for ( int rn = 1 ; rn <= nq ; rn ++ ) 
	{
		if ( q[rn].op == 1 ) 
		{
			int x = q [rn].x , d = q [rn].d , w = q [rn].w ; 
			if ( d == 0 ) 
			{
				a [x] = 1ll*a[x]*w%mod ; 
				continue ; 
			}
			if ( speical [x] == false ) update_near (x,d,w) ;
			else lazy_val [x] = 1ll*lazy_val[x]*w%mod ; 	
		}
		else 
		{
			int x = q [rn].x ; 
			int res = 1ll*a [x]*lazy_val[x]%mod ; 
			for ( auto v : vertex_special ) 
			{
				if ( adj [x][v] ) res = 1ll*res*lazy_val[v]%mod ; 
			}
			cout << res << "\n" ; 
		}
	}
}
int main ( ) 
{
	ios_base :: sync_with_stdio (0) ; 
	cin.tie(0) ; cout.tie(0) ;
//	rf () ; 
	cin >> n >> mod ; 
	for ( int i = 1 ; i < n ; i ++ ) 
	{
		int u , v ; cin >> u >> v ; 
		adjList [u] . pb (v) ; 
		adjList [v] . pb (u) ; 
	}
	
	for ( int i = 1 ; i <= n ; i ++ ) cin >> a [i] ; 
	
	cin >> nq ; 
	for ( int i = 1 ; i <= nq ; i ++ ) 
	{
		cin >> q [i].op ; 
		if ( q[i].op == 1 ) 
		{
			cin >> q[i].x >> q[i].d >> q[i].w ; 
		}
		else cin >> q[i].x ; 
	}
 
	if ( n <= 1000 && nq <= 1000 ) sub1 () ; 
	else if ( check_sub2 () ) sub2 () ; 
}
 
 
 
 
//-std=c++11

Compilation message

sprinkler.cpp: In function 'void rf()':
sprinkler.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 4 ms 14684 KB Output is correct
6 Correct 6 ms 14784 KB Output is correct
7 Correct 8 ms 14684 KB Output is correct
8 Correct 7 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 3 ms 14684 KB Output is correct
11 Correct 3 ms 14684 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 3 ms 14684 KB Output is correct
14 Correct 3 ms 14684 KB Output is correct
15 Correct 3 ms 14684 KB Output is correct
16 Correct 3 ms 14780 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 3 ms 14684 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 3 ms 14684 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
23 Correct 3 ms 14684 KB Output is correct
24 Correct 3 ms 14684 KB Output is correct
25 Correct 3 ms 14684 KB Output is correct
26 Correct 3 ms 14680 KB Output is correct
27 Correct 3 ms 14680 KB Output is correct
28 Correct 3 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 257 ms 59068 KB Output is correct
3 Correct 279 ms 55908 KB Output is correct
4 Correct 270 ms 57952 KB Output is correct
5 Correct 266 ms 57628 KB Output is correct
6 Correct 265 ms 57584 KB Output is correct
7 Correct 266 ms 57920 KB Output is correct
8 Correct 337 ms 58148 KB Output is correct
9 Correct 244 ms 58992 KB Output is correct
10 Correct 270 ms 55960 KB Output is correct
11 Correct 261 ms 59080 KB Output is correct
12 Correct 281 ms 55848 KB Output is correct
13 Correct 314 ms 56880 KB Output is correct
14 Correct 330 ms 60120 KB Output is correct
15 Correct 353 ms 70484 KB Output is correct
16 Correct 440 ms 112720 KB Output is correct
17 Correct 668 ms 205708 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 3 ms 14744 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 3 ms 14680 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Correct 257 ms 59068 KB Output is correct
3 Correct 279 ms 55908 KB Output is correct
4 Correct 270 ms 57952 KB Output is correct
5 Correct 266 ms 57628 KB Output is correct
6 Correct 265 ms 57584 KB Output is correct
7 Correct 266 ms 57920 KB Output is correct
8 Correct 337 ms 58148 KB Output is correct
9 Correct 244 ms 58992 KB Output is correct
10 Correct 270 ms 55960 KB Output is correct
11 Correct 261 ms 59080 KB Output is correct
12 Correct 281 ms 55848 KB Output is correct
13 Correct 314 ms 56880 KB Output is correct
14 Correct 330 ms 60120 KB Output is correct
15 Correct 353 ms 70484 KB Output is correct
16 Correct 440 ms 112720 KB Output is correct
17 Correct 668 ms 205708 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 3 ms 14744 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 3 ms 14680 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
23 Correct 3 ms 14680 KB Output is correct
24 Incorrect 119 ms 33468 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14684 KB Output is correct
2 Incorrect 110 ms 25048 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14680 KB Output is correct
2 Incorrect 105 ms 25172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 3 ms 14684 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 3 ms 14684 KB Output is correct
5 Correct 4 ms 14684 KB Output is correct
6 Correct 6 ms 14784 KB Output is correct
7 Correct 8 ms 14684 KB Output is correct
8 Correct 7 ms 14684 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 3 ms 14684 KB Output is correct
11 Correct 3 ms 14684 KB Output is correct
12 Correct 3 ms 14684 KB Output is correct
13 Correct 3 ms 14684 KB Output is correct
14 Correct 3 ms 14684 KB Output is correct
15 Correct 3 ms 14684 KB Output is correct
16 Correct 3 ms 14780 KB Output is correct
17 Correct 3 ms 14684 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 3 ms 14684 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 3 ms 14684 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
23 Correct 3 ms 14684 KB Output is correct
24 Correct 3 ms 14684 KB Output is correct
25 Correct 3 ms 14684 KB Output is correct
26 Correct 3 ms 14680 KB Output is correct
27 Correct 3 ms 14680 KB Output is correct
28 Correct 3 ms 14680 KB Output is correct
29 Correct 3 ms 14680 KB Output is correct
30 Correct 257 ms 59068 KB Output is correct
31 Correct 279 ms 55908 KB Output is correct
32 Correct 270 ms 57952 KB Output is correct
33 Correct 266 ms 57628 KB Output is correct
34 Correct 265 ms 57584 KB Output is correct
35 Correct 266 ms 57920 KB Output is correct
36 Correct 337 ms 58148 KB Output is correct
37 Correct 244 ms 58992 KB Output is correct
38 Correct 270 ms 55960 KB Output is correct
39 Correct 261 ms 59080 KB Output is correct
40 Correct 281 ms 55848 KB Output is correct
41 Correct 314 ms 56880 KB Output is correct
42 Correct 330 ms 60120 KB Output is correct
43 Correct 353 ms 70484 KB Output is correct
44 Correct 440 ms 112720 KB Output is correct
45 Correct 668 ms 205708 KB Output is correct
46 Correct 3 ms 14684 KB Output is correct
47 Correct 3 ms 14744 KB Output is correct
48 Correct 3 ms 14684 KB Output is correct
49 Correct 3 ms 14680 KB Output is correct
50 Correct 3 ms 14684 KB Output is correct
51 Correct 3 ms 14680 KB Output is correct
52 Incorrect 119 ms 33468 KB Output isn't correct
53 Halted 0 ms 0 KB -