답안 #876630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876630 2023-11-22T06:24:25 Z n3rm1n Sprinkler (JOI22_sprinkler) C++17
100 / 100
651 ms 187984 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

const long long MAXN = 4e5;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

long long n, mod;
vector < long long > g[MAXN];
long long h[MAXN];

void read()
{
    cin >> n >> mod;
    long long xx, yy;
    for (long long i = 1; i < n; ++ i)
    {
        cin >> xx >> yy;
        g[xx].push_back(yy);
        g[yy].push_back(xx);
    }
    for (long long i = 1; i <= n; ++ i)
        cin >> h[i];
}

///long long tin[MAXN], tout[MAXN];
long long used[MAXN];
long long p[MAXN];
///vector < long long > on_lvls[MAXN];
long long timerr = 0;
void dfs(long long beg, long long parent, long long depth)
{
   /// tin[beg] = timerr;
    p[beg] = parent;
    used[beg] = 1;
    ///on_lvls[depth].push_back(beg);
    long long nb;
    /// children = 0;
    for (long long i = 0; i < g[beg].size(); ++ i)
    {
        nb = g[beg][i];
        if(!used[nb])
        {
           /// children ++;
            dfs(nb, beg, depth + 1);
        }
    }
    /**if(children)
    {
        timerr ++;
        tout[beg] = timerr;
    }*/
}

long long x, d, w;
long long upd[MAXN][88];

void print_upd()
{
    for (long long i = 1; i <= n; ++ i)
    {
        cout << "upd for vertex " << i << " " << endl;
        cout << "depth : ";
        for (long long j = 0; j <= 3; ++ j)
            cout << upd[i][j] << ", ";
        cout << endl;
    }
}
void update_arrays()
{
   /// cout << "***" << endl;
    long long vertex = x, depth = d;
    while(vertex != 1 && depth >= 0)
    {

        upd[vertex][depth] *= w;
        upd[vertex][depth] %= mod;
        if(depth)
        {
            upd[vertex][depth-1] *= w;
            upd[vertex][depth-1] %= mod;
        }
        ///cout << vertex << " " << depth << " " << upd[vertex][depth] << endl;
        ///cout << vertex << " " << depth-1 << " " << upd[vertex][depth-1] << endl;
        vertex = p[vertex];
        depth --;
    }
   if(vertex == 1)
   {
       for (long long i = 0; i <= depth; ++ i)
        {
            upd[1][i] *= w;
            upd[1][i] %= mod;
        }
   }
}
void solve_query()
{
    long long anc = x, lvl_diff = 0;
    long long ans = h[x];
    //cout << "solving for v = " << anc << endl;
    while(anc && lvl_diff <= 40)
    {
        //cout << "anc = " << anc << " " << "mult is " << upd[anc][lvl_diff] << endl;
        ans = ans * upd[anc][lvl_diff];
        ans %= mod;
        anc = p[anc];
        lvl_diff ++;
    }
    cout << ans << endl;
}
void queries()
{
    long long q;
    cin >> q;
    long long type;
    while(q --)
    {
        cin >> type;
        if(type == 1)
        {
            cin >> x >> d >> w;
            update_arrays();
            ///prlong long_upd();
        }
        else
        {
            cin >> x;
            solve_query();
        }
    }
}
int main()
{
    speed();

    read();
    for (long long i = 1; i <= n; ++ i)
        for (long long j = 0; j <= 80; ++ j)
            upd[i][j] = 1;
    dfs(1, 0, 1);
    queries();
    return 0;

}

Compilation message

sprinkler.cpp: In function 'void dfs(long long int, long long int, long long int)':
sprinkler.cpp:46:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (long long i = 0; i < g[beg].size(); ++ i)
      |                           ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17496 KB Output is correct
2 Correct 3 ms 17500 KB Output is correct
3 Correct 3 ms 17500 KB Output is correct
4 Correct 4 ms 19804 KB Output is correct
5 Correct 4 ms 20056 KB Output is correct
6 Correct 4 ms 19660 KB Output is correct
7 Correct 4 ms 19804 KB Output is correct
8 Correct 4 ms 19804 KB Output is correct
9 Correct 3 ms 17500 KB Output is correct
10 Correct 3 ms 17500 KB Output is correct
11 Correct 3 ms 17500 KB Output is correct
12 Correct 3 ms 17500 KB Output is correct
13 Correct 3 ms 17604 KB Output is correct
14 Correct 3 ms 17496 KB Output is correct
15 Correct 3 ms 17500 KB Output is correct
16 Correct 3 ms 17500 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 3 ms 17500 KB Output is correct
19 Correct 3 ms 17500 KB Output is correct
20 Correct 3 ms 17500 KB Output is correct
21 Correct 3 ms 17500 KB Output is correct
22 Correct 3 ms 17500 KB Output is correct
23 Correct 3 ms 17500 KB Output is correct
24 Correct 3 ms 17500 KB Output is correct
25 Correct 5 ms 17344 KB Output is correct
26 Correct 3 ms 17500 KB Output is correct
27 Correct 3 ms 17496 KB Output is correct
28 Correct 3 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17500 KB Output is correct
2 Correct 357 ms 173368 KB Output is correct
3 Correct 257 ms 172168 KB Output is correct
4 Correct 420 ms 179536 KB Output is correct
5 Correct 317 ms 172880 KB Output is correct
6 Correct 248 ms 172664 KB Output is correct
7 Correct 275 ms 173136 KB Output is correct
8 Correct 205 ms 173504 KB Output is correct
9 Correct 452 ms 184524 KB Output is correct
10 Correct 289 ms 182188 KB Output is correct
11 Correct 366 ms 173296 KB Output is correct
12 Correct 281 ms 177652 KB Output is correct
13 Correct 187 ms 177812 KB Output is correct
14 Correct 190 ms 178364 KB Output is correct
15 Correct 186 ms 177648 KB Output is correct
16 Correct 188 ms 178004 KB Output is correct
17 Correct 197 ms 178640 KB Output is correct
18 Correct 4 ms 18008 KB Output is correct
19 Correct 3 ms 17588 KB Output is correct
20 Correct 3 ms 17500 KB Output is correct
21 Correct 3 ms 17500 KB Output is correct
22 Correct 3 ms 17752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17500 KB Output is correct
2 Correct 357 ms 173368 KB Output is correct
3 Correct 257 ms 172168 KB Output is correct
4 Correct 420 ms 179536 KB Output is correct
5 Correct 317 ms 172880 KB Output is correct
6 Correct 248 ms 172664 KB Output is correct
7 Correct 275 ms 173136 KB Output is correct
8 Correct 205 ms 173504 KB Output is correct
9 Correct 452 ms 184524 KB Output is correct
10 Correct 289 ms 182188 KB Output is correct
11 Correct 366 ms 173296 KB Output is correct
12 Correct 281 ms 177652 KB Output is correct
13 Correct 187 ms 177812 KB Output is correct
14 Correct 190 ms 178364 KB Output is correct
15 Correct 186 ms 177648 KB Output is correct
16 Correct 188 ms 178004 KB Output is correct
17 Correct 197 ms 178640 KB Output is correct
18 Correct 4 ms 18008 KB Output is correct
19 Correct 3 ms 17588 KB Output is correct
20 Correct 3 ms 17500 KB Output is correct
21 Correct 3 ms 17500 KB Output is correct
22 Correct 3 ms 17752 KB Output is correct
23 Correct 3 ms 17496 KB Output is correct
24 Correct 391 ms 177372 KB Output is correct
25 Correct 262 ms 177748 KB Output is correct
26 Correct 381 ms 187984 KB Output is correct
27 Correct 307 ms 177404 KB Output is correct
28 Correct 246 ms 177744 KB Output is correct
29 Correct 245 ms 177488 KB Output is correct
30 Correct 210 ms 178128 KB Output is correct
31 Correct 445 ms 184688 KB Output is correct
32 Correct 298 ms 187936 KB Output is correct
33 Correct 373 ms 177396 KB Output is correct
34 Correct 276 ms 177744 KB Output is correct
35 Correct 3 ms 17500 KB Output is correct
36 Correct 4 ms 17756 KB Output is correct
37 Correct 3 ms 17500 KB Output is correct
38 Correct 3 ms 17500 KB Output is correct
39 Correct 4 ms 17500 KB Output is correct
40 Correct 4 ms 17572 KB Output is correct
41 Correct 4 ms 17500 KB Output is correct
42 Correct 3 ms 17596 KB Output is correct
43 Correct 4 ms 17500 KB Output is correct
44 Correct 3 ms 17500 KB Output is correct
45 Correct 3 ms 17500 KB Output is correct
46 Correct 3 ms 17500 KB Output is correct
47 Correct 3 ms 17548 KB Output is correct
48 Correct 3 ms 17496 KB Output is correct
49 Correct 3 ms 17496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17500 KB Output is correct
2 Correct 543 ms 181604 KB Output is correct
3 Correct 619 ms 178568 KB Output is correct
4 Correct 462 ms 179172 KB Output is correct
5 Correct 393 ms 170580 KB Output is correct
6 Correct 271 ms 170512 KB Output is correct
7 Correct 254 ms 170808 KB Output is correct
8 Correct 214 ms 171056 KB Output is correct
9 Correct 517 ms 178004 KB Output is correct
10 Correct 585 ms 180304 KB Output is correct
11 Correct 389 ms 170856 KB Output is correct
12 Correct 409 ms 170840 KB Output is correct
13 Correct 331 ms 171856 KB Output is correct
14 Correct 330 ms 172372 KB Output is correct
15 Correct 3 ms 17500 KB Output is correct
16 Correct 3 ms 17500 KB Output is correct
17 Correct 3 ms 17500 KB Output is correct
18 Correct 3 ms 17460 KB Output is correct
19 Correct 4 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17500 KB Output is correct
2 Correct 523 ms 180356 KB Output is correct
3 Correct 599 ms 180712 KB Output is correct
4 Correct 459 ms 182620 KB Output is correct
5 Correct 364 ms 176212 KB Output is correct
6 Correct 290 ms 176464 KB Output is correct
7 Correct 271 ms 176148 KB Output is correct
8 Correct 213 ms 176532 KB Output is correct
9 Correct 482 ms 187216 KB Output is correct
10 Correct 630 ms 185784 KB Output is correct
11 Correct 401 ms 177152 KB Output is correct
12 Correct 405 ms 175444 KB Output is correct
13 Correct 352 ms 176024 KB Output is correct
14 Correct 342 ms 176976 KB Output is correct
15 Correct 4 ms 17500 KB Output is correct
16 Correct 4 ms 17500 KB Output is correct
17 Correct 3 ms 17496 KB Output is correct
18 Correct 4 ms 17500 KB Output is correct
19 Correct 3 ms 17500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17496 KB Output is correct
2 Correct 3 ms 17500 KB Output is correct
3 Correct 3 ms 17500 KB Output is correct
4 Correct 4 ms 19804 KB Output is correct
5 Correct 4 ms 20056 KB Output is correct
6 Correct 4 ms 19660 KB Output is correct
7 Correct 4 ms 19804 KB Output is correct
8 Correct 4 ms 19804 KB Output is correct
9 Correct 3 ms 17500 KB Output is correct
10 Correct 3 ms 17500 KB Output is correct
11 Correct 3 ms 17500 KB Output is correct
12 Correct 3 ms 17500 KB Output is correct
13 Correct 3 ms 17604 KB Output is correct
14 Correct 3 ms 17496 KB Output is correct
15 Correct 3 ms 17500 KB Output is correct
16 Correct 3 ms 17500 KB Output is correct
17 Correct 4 ms 18012 KB Output is correct
18 Correct 3 ms 17500 KB Output is correct
19 Correct 3 ms 17500 KB Output is correct
20 Correct 3 ms 17500 KB Output is correct
21 Correct 3 ms 17500 KB Output is correct
22 Correct 3 ms 17500 KB Output is correct
23 Correct 3 ms 17500 KB Output is correct
24 Correct 3 ms 17500 KB Output is correct
25 Correct 5 ms 17344 KB Output is correct
26 Correct 3 ms 17500 KB Output is correct
27 Correct 3 ms 17496 KB Output is correct
28 Correct 3 ms 17500 KB Output is correct
29 Correct 3 ms 17500 KB Output is correct
30 Correct 357 ms 173368 KB Output is correct
31 Correct 257 ms 172168 KB Output is correct
32 Correct 420 ms 179536 KB Output is correct
33 Correct 317 ms 172880 KB Output is correct
34 Correct 248 ms 172664 KB Output is correct
35 Correct 275 ms 173136 KB Output is correct
36 Correct 205 ms 173504 KB Output is correct
37 Correct 452 ms 184524 KB Output is correct
38 Correct 289 ms 182188 KB Output is correct
39 Correct 366 ms 173296 KB Output is correct
40 Correct 281 ms 177652 KB Output is correct
41 Correct 187 ms 177812 KB Output is correct
42 Correct 190 ms 178364 KB Output is correct
43 Correct 186 ms 177648 KB Output is correct
44 Correct 188 ms 178004 KB Output is correct
45 Correct 197 ms 178640 KB Output is correct
46 Correct 4 ms 18008 KB Output is correct
47 Correct 3 ms 17588 KB Output is correct
48 Correct 3 ms 17500 KB Output is correct
49 Correct 3 ms 17500 KB Output is correct
50 Correct 3 ms 17752 KB Output is correct
51 Correct 3 ms 17496 KB Output is correct
52 Correct 391 ms 177372 KB Output is correct
53 Correct 262 ms 177748 KB Output is correct
54 Correct 381 ms 187984 KB Output is correct
55 Correct 307 ms 177404 KB Output is correct
56 Correct 246 ms 177744 KB Output is correct
57 Correct 245 ms 177488 KB Output is correct
58 Correct 210 ms 178128 KB Output is correct
59 Correct 445 ms 184688 KB Output is correct
60 Correct 298 ms 187936 KB Output is correct
61 Correct 373 ms 177396 KB Output is correct
62 Correct 276 ms 177744 KB Output is correct
63 Correct 3 ms 17500 KB Output is correct
64 Correct 4 ms 17756 KB Output is correct
65 Correct 3 ms 17500 KB Output is correct
66 Correct 3 ms 17500 KB Output is correct
67 Correct 4 ms 17500 KB Output is correct
68 Correct 4 ms 17572 KB Output is correct
69 Correct 4 ms 17500 KB Output is correct
70 Correct 3 ms 17596 KB Output is correct
71 Correct 4 ms 17500 KB Output is correct
72 Correct 3 ms 17500 KB Output is correct
73 Correct 3 ms 17500 KB Output is correct
74 Correct 3 ms 17500 KB Output is correct
75 Correct 3 ms 17548 KB Output is correct
76 Correct 3 ms 17496 KB Output is correct
77 Correct 3 ms 17496 KB Output is correct
78 Correct 3 ms 17500 KB Output is correct
79 Correct 543 ms 181604 KB Output is correct
80 Correct 619 ms 178568 KB Output is correct
81 Correct 462 ms 179172 KB Output is correct
82 Correct 393 ms 170580 KB Output is correct
83 Correct 271 ms 170512 KB Output is correct
84 Correct 254 ms 170808 KB Output is correct
85 Correct 214 ms 171056 KB Output is correct
86 Correct 517 ms 178004 KB Output is correct
87 Correct 585 ms 180304 KB Output is correct
88 Correct 389 ms 170856 KB Output is correct
89 Correct 409 ms 170840 KB Output is correct
90 Correct 331 ms 171856 KB Output is correct
91 Correct 330 ms 172372 KB Output is correct
92 Correct 3 ms 17500 KB Output is correct
93 Correct 3 ms 17500 KB Output is correct
94 Correct 3 ms 17500 KB Output is correct
95 Correct 3 ms 17460 KB Output is correct
96 Correct 4 ms 17500 KB Output is correct
97 Correct 3 ms 17500 KB Output is correct
98 Correct 523 ms 180356 KB Output is correct
99 Correct 599 ms 180712 KB Output is correct
100 Correct 459 ms 182620 KB Output is correct
101 Correct 364 ms 176212 KB Output is correct
102 Correct 290 ms 176464 KB Output is correct
103 Correct 271 ms 176148 KB Output is correct
104 Correct 213 ms 176532 KB Output is correct
105 Correct 482 ms 187216 KB Output is correct
106 Correct 630 ms 185784 KB Output is correct
107 Correct 401 ms 177152 KB Output is correct
108 Correct 405 ms 175444 KB Output is correct
109 Correct 352 ms 176024 KB Output is correct
110 Correct 342 ms 176976 KB Output is correct
111 Correct 4 ms 17500 KB Output is correct
112 Correct 4 ms 17500 KB Output is correct
113 Correct 3 ms 17496 KB Output is correct
114 Correct 4 ms 17500 KB Output is correct
115 Correct 3 ms 17500 KB Output is correct
116 Correct 395 ms 175300 KB Output is correct
117 Correct 496 ms 177980 KB Output is correct
118 Correct 491 ms 187828 KB Output is correct
119 Correct 391 ms 177656 KB Output is correct
120 Correct 300 ms 177232 KB Output is correct
121 Correct 329 ms 178004 KB Output is correct
122 Correct 237 ms 178172 KB Output is correct
123 Correct 543 ms 185952 KB Output is correct
124 Correct 651 ms 184088 KB Output is correct
125 Correct 391 ms 176464 KB Output is correct
126 Correct 496 ms 178024 KB Output is correct
127 Correct 497 ms 178260 KB Output is correct
128 Correct 444 ms 178824 KB Output is correct
129 Correct 453 ms 179988 KB Output is correct