Submission #676116

# Submission time Handle Problem Language Result Execution time Memory
676116 2022-12-29T11:07:42 Z abysmal Sprinkler (JOI22_sprinkler) C++14
100 / 100
1992 ms 69844 KB
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>

using namespace std;

const int64_t INF = (int64_t) 1e6 + 1;
const int64_t mINF = 41;
const int64_t MOD = (int64_t) 1e9 + 7;
const int nbit = 11;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};
// 0 right // 1 down // 2 left // 3 up

struct Node
{
    int u;
    int w;

    Node(int u_, int w_) : u(u_), w(w_) {}

    bool operator < (const Node& o) const
    {
        return w > o.w;
    }
};

struct Solution
{
    int n;
    int64_t l;
    vector<int> p;
    vector<int> h;
    vector<vector<int> > mul;
    vector<vector<int> > adj;
    Solution() {}

    void solve()
    {
        cin >> n >> l;
        h.resize(n);
        adj.resize(n);
        p.resize(n, -1);
        mul.resize(n, vector<int>(mINF, 1));

        for(int i = 0; i < n - 1; i++)
        {
            int u;
            int v;
            cin >> u >> v;
            u--; v--;

            adj[u].push_back(v);
            adj[v].push_back(u);
        }

        for(int i = 0; i < n; i++)
        {
            cin >> h[i];
        }

        DFS();
        int q;
        cin >> q;
        for(int i = 0; i < q; i++)
        {
            int t;
            cin >> t;

            if(t == 1)
            {
                int u;
                int d;
                int w;
                cin >> u >> d >> w;
                u--;

                while(u != -1 && d >= 0)
                {
                    mul[u][d] = modmul(mul[u][d], w);
//                    cerr << "u = " << u << " ; d = " << d << " ; w = " << w << "\n";
                    d--;
                    u = p[u];
                }

//                cerr << "\n";
            }
            else
            {
                int u;
                cin >> u;
                u--;

                int ans = h[u];
                int d = 0;
//                cerr << "2\n";
                while(p[u] != -1 && d < mINF)
                {
                    ans = modmul(ans, mul[u][d]);
//                    cerr << "u = " << u << " ; d = " << d << " ; w = " << mul[u][d] << "\n";
                    if(d + 1 < mINF)
                    {
                        ans = modmul(ans, mul[u][d + 1]);
//                        cerr << "w2 = " << mul[u][d + 1] << "\n";
                    }

                    d++;
                    u = p[u];
                }

                while(d < mINF)
                {
//                    cerr << "u = " << u << " ; d = " << d << " ; w = " << mul[u][d] << "\n";
                    ans = modmul(ans, mul[u][d]);

                    d++;
                }

//                cerr << "\n";
                cout << ans << "\n";
            }
        }
    }

    void DFS(int u = 0)
    {
        for(int i = 0; i < (int) adj[u].size(); i++)
        {
            int v = adj[u][i];

            if(v == p[u]) continue;

            p[v] = u;
            DFS(v);
        }
    }

    int modsub(int t1, int t2)
    {
        int res = t1 - t2;
        if(res < 0) res += MOD;

        return res;
    }

    int modadd(int t1, int t2)
    {
        int res = t1 + t2;
        if(res >= MOD) res -= MOD;

        return res;
    }

    int modmul(int t1, int t2)
    {
        int64_t res = 1LL * t1 * t2;
        return (res % l);
    }

    bool BIT(int& mask, int& j)
    {
        return (mask & MASK(j));
    }

    int64_t MASK(int64_t j)
    {
        return (1LL << j);
    }
};

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

//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
}

int main()
{
    __startup();
    int t = 1;
//    cin >> t;

    for(int i = 1; i <= t; i++)
    {
        Solution().solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 702 ms 63984 KB Output is correct
3 Correct 417 ms 64332 KB Output is correct
4 Correct 673 ms 67944 KB Output is correct
5 Correct 583 ms 64120 KB Output is correct
6 Correct 402 ms 63672 KB Output is correct
7 Correct 429 ms 64484 KB Output is correct
8 Correct 338 ms 64836 KB Output is correct
9 Correct 888 ms 69544 KB Output is correct
10 Correct 475 ms 69844 KB Output is correct
11 Correct 695 ms 63780 KB Output is correct
12 Correct 425 ms 64304 KB Output is correct
13 Correct 254 ms 64576 KB Output is correct
14 Correct 249 ms 65060 KB Output is correct
15 Correct 293 ms 64380 KB Output is correct
16 Correct 272 ms 64824 KB Output is correct
17 Correct 261 ms 65356 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 702 ms 63984 KB Output is correct
3 Correct 417 ms 64332 KB Output is correct
4 Correct 673 ms 67944 KB Output is correct
5 Correct 583 ms 64120 KB Output is correct
6 Correct 402 ms 63672 KB Output is correct
7 Correct 429 ms 64484 KB Output is correct
8 Correct 338 ms 64836 KB Output is correct
9 Correct 888 ms 69544 KB Output is correct
10 Correct 475 ms 69844 KB Output is correct
11 Correct 695 ms 63780 KB Output is correct
12 Correct 425 ms 64304 KB Output is correct
13 Correct 254 ms 64576 KB Output is correct
14 Correct 249 ms 65060 KB Output is correct
15 Correct 293 ms 64380 KB Output is correct
16 Correct 272 ms 64824 KB Output is correct
17 Correct 261 ms 65356 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 706 ms 63924 KB Output is correct
25 Correct 479 ms 64308 KB Output is correct
26 Correct 700 ms 69744 KB Output is correct
27 Correct 618 ms 64040 KB Output is correct
28 Correct 470 ms 64204 KB Output is correct
29 Correct 401 ms 63932 KB Output is correct
30 Correct 366 ms 64812 KB Output is correct
31 Correct 964 ms 68056 KB Output is correct
32 Correct 524 ms 69832 KB Output is correct
33 Correct 690 ms 63744 KB Output is correct
34 Correct 505 ms 64292 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 328 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 324 KB Output is correct
49 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1029 ms 66792 KB Output is correct
3 Correct 1535 ms 66080 KB Output is correct
4 Correct 990 ms 65824 KB Output is correct
5 Correct 814 ms 61176 KB Output is correct
6 Correct 512 ms 61188 KB Output is correct
7 Correct 430 ms 61384 KB Output is correct
8 Correct 358 ms 61860 KB Output is correct
9 Correct 1126 ms 65012 KB Output is correct
10 Correct 1992 ms 66916 KB Output is correct
11 Correct 829 ms 60672 KB Output is correct
12 Correct 1112 ms 61688 KB Output is correct
13 Correct 669 ms 62516 KB Output is correct
14 Correct 762 ms 63148 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1090 ms 67456 KB Output is correct
3 Correct 1595 ms 64956 KB Output is correct
4 Correct 1006 ms 66204 KB Output is correct
5 Correct 821 ms 62856 KB Output is correct
6 Correct 566 ms 62816 KB Output is correct
7 Correct 515 ms 62568 KB Output is correct
8 Correct 350 ms 62840 KB Output is correct
9 Correct 1120 ms 68996 KB Output is correct
10 Correct 1703 ms 67508 KB Output is correct
11 Correct 830 ms 63436 KB Output is correct
12 Correct 1166 ms 61920 KB Output is correct
13 Correct 692 ms 62672 KB Output is correct
14 Correct 711 ms 63160 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 702 ms 63984 KB Output is correct
31 Correct 417 ms 64332 KB Output is correct
32 Correct 673 ms 67944 KB Output is correct
33 Correct 583 ms 64120 KB Output is correct
34 Correct 402 ms 63672 KB Output is correct
35 Correct 429 ms 64484 KB Output is correct
36 Correct 338 ms 64836 KB Output is correct
37 Correct 888 ms 69544 KB Output is correct
38 Correct 475 ms 69844 KB Output is correct
39 Correct 695 ms 63780 KB Output is correct
40 Correct 425 ms 64304 KB Output is correct
41 Correct 254 ms 64576 KB Output is correct
42 Correct 249 ms 65060 KB Output is correct
43 Correct 293 ms 64380 KB Output is correct
44 Correct 272 ms 64824 KB Output is correct
45 Correct 261 ms 65356 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 328 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 706 ms 63924 KB Output is correct
53 Correct 479 ms 64308 KB Output is correct
54 Correct 700 ms 69744 KB Output is correct
55 Correct 618 ms 64040 KB Output is correct
56 Correct 470 ms 64204 KB Output is correct
57 Correct 401 ms 63932 KB Output is correct
58 Correct 366 ms 64812 KB Output is correct
59 Correct 964 ms 68056 KB Output is correct
60 Correct 524 ms 69832 KB Output is correct
61 Correct 690 ms 63744 KB Output is correct
62 Correct 505 ms 64292 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 328 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 ms 212 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 324 KB Output is correct
77 Correct 1 ms 324 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 1029 ms 66792 KB Output is correct
80 Correct 1535 ms 66080 KB Output is correct
81 Correct 990 ms 65824 KB Output is correct
82 Correct 814 ms 61176 KB Output is correct
83 Correct 512 ms 61188 KB Output is correct
84 Correct 430 ms 61384 KB Output is correct
85 Correct 358 ms 61860 KB Output is correct
86 Correct 1126 ms 65012 KB Output is correct
87 Correct 1992 ms 66916 KB Output is correct
88 Correct 829 ms 60672 KB Output is correct
89 Correct 1112 ms 61688 KB Output is correct
90 Correct 669 ms 62516 KB Output is correct
91 Correct 762 ms 63148 KB Output is correct
92 Correct 1 ms 212 KB Output is correct
93 Correct 1 ms 212 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 324 KB Output is correct
97 Correct 0 ms 212 KB Output is correct
98 Correct 1090 ms 67456 KB Output is correct
99 Correct 1595 ms 64956 KB Output is correct
100 Correct 1006 ms 66204 KB Output is correct
101 Correct 821 ms 62856 KB Output is correct
102 Correct 566 ms 62816 KB Output is correct
103 Correct 515 ms 62568 KB Output is correct
104 Correct 350 ms 62840 KB Output is correct
105 Correct 1120 ms 68996 KB Output is correct
106 Correct 1703 ms 67508 KB Output is correct
107 Correct 830 ms 63436 KB Output is correct
108 Correct 1166 ms 61920 KB Output is correct
109 Correct 692 ms 62672 KB Output is correct
110 Correct 711 ms 63160 KB Output is correct
111 Correct 1 ms 212 KB Output is correct
112 Correct 1 ms 328 KB Output is correct
113 Correct 1 ms 340 KB Output is correct
114 Correct 1 ms 316 KB Output is correct
115 Correct 1 ms 340 KB Output is correct
116 Correct 813 ms 61820 KB Output is correct
117 Correct 1202 ms 64456 KB Output is correct
118 Correct 1006 ms 69800 KB Output is correct
119 Correct 805 ms 64164 KB Output is correct
120 Correct 575 ms 63756 KB Output is correct
121 Correct 523 ms 64572 KB Output is correct
122 Correct 381 ms 64772 KB Output is correct
123 Correct 1090 ms 68468 KB Output is correct
124 Correct 1595 ms 67860 KB Output is correct
125 Correct 808 ms 63052 KB Output is correct
126 Correct 1197 ms 64272 KB Output is correct
127 Correct 1170 ms 64912 KB Output is correct
128 Correct 727 ms 65472 KB Output is correct
129 Correct 744 ms 65908 KB Output is correct