답안 #763703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763703 2023-06-22T16:20:09 Z anhduc2701 Tourism (JOI23_tourism) C++17
100 / 100
1014 ms 111740 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI acos(-1.0)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x, i) (1 & ((x) >> (i)))
#define MASK(x) (1LL << (x))
#define task "tnc"
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
const int mo = 998244353;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using pii = pair<pair<ll, ll>, ll>;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int tin[maxn];
int tout[maxn];
int eu[maxn];
int n, m, q;
int ti = 0;
vector<int> G[maxn];
int h[maxn];
void dfs(int u, int pa)
{
    tin[u] = ++ti;
    eu[ti] = u;
    for (auto v : G[u])
    {
        if (v == pa)
            continue;
        h[v] = h[u] + 1;
        dfs(v, u);
        eu[++ti] = u;
    }
}
pair<int, int> rmq[maxn][19];
void init()
{
    for (int i = 1; i <= ti; i++)
    {
        rmq[i][0] = {tin[eu[i]], eu[i]};
    }
    for (int j = 1; (1 << j) <= ti; j++)
    {
        for (int i = 1; i <= ti; i++)
        {
            rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
        }
    }
}
int LCA(int u, int v)
{
    if (tin[u] > tin[v])
        swap(u, v);
    int k = 31 - __builtin_clz(tin[v] - tin[u] + 1);
    return min(rmq[tin[u]][k], rmq[tin[v] - (1 << k) + 1][k]).se;
}
struct que
{
    int l, r, id;
    que() {}
    que(int _l, int _r, int _id)
    {
        l = _l;
        r = _r;
        id = _id;
    }
};
// BIT
int bit[maxn];
void update(int id, int val)
{
    for (id; id >= 1; id -= id & (-id))
    {
        bit[id] += val;
    }
}
int get(int id)
{
    int res = 0;
    for (id; id <= m; id += id & (-id))
    {
        res += bit[id];
    }
    return res;
}
vector<que> st[maxn];
void update(int l, int r, int u, int v, int id)
{
    if (l <= r)
    {
        int mid = (l + r) / 2;
        if (u <= mid && mid <= v)
        {
            st[mid].pb(que(u, v, id));
            return;
        }
        if (v < mid)
            update(l, mid - 1, u, v, id);
        else
            update(mid + 1, r, u, v, id);
    }
}
vector<int> d[maxn];
vector<int> adj[maxn];
int befmid[maxn];
int aftmid[maxn];
int prefbef[maxn];
int prefaft[maxn];
vector<pair<int, int>> ask[maxn];
vector<pair<int, int>> ques[maxn];
void dfs1(int u, int pa, int mid, int l, int r)
{
    auto z = lower_bound(d[u].begin(), d[u].end(), mid) - d[u].begin();

    if (z < d[u].size())
    {
        aftmid[u] = d[u][z];
    }
    else
    {
        aftmid[u] = 1e9;
    }
    if (z != 0)
    {
        z--;
        befmid[u] = d[u][z];
    }

    for (auto v : adj[u])
    {
        if (v == pa)
            continue;
        dfs1(v, u, mid, l, r);

        befmid[u] = max(befmid[v], befmid[u]);
        aftmid[u] = min(aftmid[u], aftmid[v]);

        if (befmid[v] >= l)
        {
            prefbef[befmid[v]] += abs(h[v] - h[u]);
        }

        if (aftmid[v] <= r)
        {
            prefaft[aftmid[v]] += abs(h[v] - h[u]);
        }

        if (befmid[v] >= l && aftmid[v] <= r)
        {
            ask[aftmid[v]].pb({befmid[v], abs(h[v] - h[u])});
        }
    }
}
int ans[maxn];
int c[maxn];
bool cmp(int u, int v)
{
    return tin[u] < tin[v];
}
void DNC(int l, int r)
{
    if (l <= r)
    {

        int mid = (l + r) / 2;
        vector<int> ver;
        for (int i = l; i <= r; i++)
        {
            ver.pb(c[i]);
        }
        sort(ver.begin(), ver.end());
        ver.resize(distance(ver.begin(), unique(ver.begin(), ver.end())));
        sort(ver.begin(), ver.end(), cmp);
        vector<int> vir;
        vir = ver;
        for (auto i = 1; i < ver.size(); i++)
        {
            vir.pb(LCA(ver[i], ver[i - 1]));
        }
        sort(vir.begin(), vir.end());
        vir.resize(distance(vir.begin(), unique(vir.begin(), vir.end())));
        sort(vir.begin(), vir.end(), cmp);

        for (int i = 1; i < vir.size(); i++)
        {
            adj[LCA(vir[i], vir[i - 1])].pb(vir[i]);
            adj[vir[i]].pb(LCA(vir[i], vir[i - 1]));
        }
        dfs1(c[mid], -1, mid, l, r);
        for (int i = mid; i >= l; i--)
        {
            prefbef[i] += prefbef[i + 1];
        }
        for (int i = mid; i <= r; i++)
        {
            prefaft[i] += prefaft[i - 1];
        }
        for (auto v : st[mid])
        {
            ques[v.r].pb({v.l, v.id});
        }
        for (int i = mid; i <= r; i++)
        {
            for (auto v : ask[i])
            {
                update(v.fi, v.se);
            }
            for (auto v : ques[i])
            {
                ans[v.se] = prefbef[v.fi] + prefaft[i] - get(v.fi);
            }
            ques[i].clear();
        }
        for (int i = mid; i >= l; i--)
        {
            prefbef[i] = 0;
        }
        for (int i = mid; i <= r; i++)
        {
            prefaft[i] = 0;
            for (auto v : ask[i])
            {
                update(v.fi, -v.se);
            }
            ask[i].clear();
        }
        for (auto v : vir)
        {
            aftmid[v] = 0;
            befmid[v] = 0;
            adj[v].clear();
        }

        if (l != r)
        {
            DNC(l, mid - 1);
            DNC(mid + 1, r);
        }
    }
}

signed main()
{
    cin.tie(0), cout.tie(0)->sync_with_stdio(0);
    cin >> n >> m >> q;
    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }
    for (int i = 1; i <= m; i++)
    {
        cin >> c[i];
        d[c[i]].pb(i);
    }
    for (int i = 1; i <= q; i++)
    {
        int l, r;
        cin >> l >> r;
        update(1, m, l, r, i);
    }
    dfs(1, -1);
    init();

    DNC(1, m);
    for (int i = 1; i <= q; i++)
    {
        cout << ans[i] + 1 << "\n";
    }
}

Compilation message

tourism.cpp: In function 'void update(int, int)':
tourism.cpp:90:10: warning: statement has no effect [-Wunused-value]
   90 |     for (id; id >= 1; id -= id & (-id))
      |          ^~
tourism.cpp: In function 'int get(int)':
tourism.cpp:98:10: warning: statement has no effect [-Wunused-value]
   98 |     for (id; id <= m; id += id & (-id))
      |          ^~
tourism.cpp: In function 'void dfs1(int, int, int, int, int)':
tourism.cpp:133:11: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |     if (z < d[u].size())
      |         ~~^~~~~~~~~~~~~
tourism.cpp: In function 'void DNC(int, int)':
tourism.cpp:194:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  194 |         for (auto i = 1; i < ver.size(); i++)
      |                          ~~^~~~~~~~~~~~
tourism.cpp:202:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  202 |         for (int i = 1; i < vir.size(); i++)
      |                         ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 42580 KB Output is correct
2 Correct 20 ms 42580 KB Output is correct
3 Correct 20 ms 42676 KB Output is correct
4 Correct 23 ms 42772 KB Output is correct
5 Correct 20 ms 42700 KB Output is correct
6 Correct 20 ms 42708 KB Output is correct
7 Correct 20 ms 42776 KB Output is correct
8 Correct 20 ms 42808 KB Output is correct
9 Correct 21 ms 42836 KB Output is correct
10 Correct 26 ms 42948 KB Output is correct
11 Correct 21 ms 42812 KB Output is correct
12 Correct 21 ms 42832 KB Output is correct
13 Correct 22 ms 42772 KB Output is correct
14 Correct 21 ms 42708 KB Output is correct
15 Correct 20 ms 42788 KB Output is correct
16 Correct 21 ms 42792 KB Output is correct
17 Correct 20 ms 42776 KB Output is correct
18 Correct 20 ms 42780 KB Output is correct
19 Correct 20 ms 42832 KB Output is correct
20 Correct 20 ms 42812 KB Output is correct
21 Correct 21 ms 42708 KB Output is correct
22 Correct 20 ms 42780 KB Output is correct
23 Correct 21 ms 42788 KB Output is correct
24 Correct 21 ms 42708 KB Output is correct
25 Correct 23 ms 42716 KB Output is correct
26 Correct 20 ms 42788 KB Output is correct
27 Correct 20 ms 42576 KB Output is correct
28 Correct 20 ms 42680 KB Output is correct
29 Correct 20 ms 42820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 42580 KB Output is correct
2 Correct 20 ms 42580 KB Output is correct
3 Correct 20 ms 42676 KB Output is correct
4 Correct 23 ms 42772 KB Output is correct
5 Correct 20 ms 42700 KB Output is correct
6 Correct 20 ms 42708 KB Output is correct
7 Correct 20 ms 42776 KB Output is correct
8 Correct 20 ms 42808 KB Output is correct
9 Correct 21 ms 42836 KB Output is correct
10 Correct 26 ms 42948 KB Output is correct
11 Correct 21 ms 42812 KB Output is correct
12 Correct 21 ms 42832 KB Output is correct
13 Correct 22 ms 42772 KB Output is correct
14 Correct 21 ms 42708 KB Output is correct
15 Correct 20 ms 42788 KB Output is correct
16 Correct 21 ms 42792 KB Output is correct
17 Correct 20 ms 42776 KB Output is correct
18 Correct 20 ms 42780 KB Output is correct
19 Correct 20 ms 42832 KB Output is correct
20 Correct 20 ms 42812 KB Output is correct
21 Correct 21 ms 42708 KB Output is correct
22 Correct 20 ms 42780 KB Output is correct
23 Correct 21 ms 42788 KB Output is correct
24 Correct 21 ms 42708 KB Output is correct
25 Correct 23 ms 42716 KB Output is correct
26 Correct 20 ms 42788 KB Output is correct
27 Correct 20 ms 42576 KB Output is correct
28 Correct 20 ms 42680 KB Output is correct
29 Correct 20 ms 42820 KB Output is correct
30 Correct 25 ms 43400 KB Output is correct
31 Correct 26 ms 43356 KB Output is correct
32 Correct 28 ms 43692 KB Output is correct
33 Correct 27 ms 43604 KB Output is correct
34 Correct 28 ms 43616 KB Output is correct
35 Correct 28 ms 43572 KB Output is correct
36 Correct 28 ms 43676 KB Output is correct
37 Correct 33 ms 43672 KB Output is correct
38 Correct 31 ms 43980 KB Output is correct
39 Correct 30 ms 43892 KB Output is correct
40 Correct 27 ms 43852 KB Output is correct
41 Correct 26 ms 43872 KB Output is correct
42 Correct 26 ms 43868 KB Output is correct
43 Correct 26 ms 43852 KB Output is correct
44 Correct 26 ms 43816 KB Output is correct
45 Correct 27 ms 43800 KB Output is correct
46 Correct 26 ms 43728 KB Output is correct
47 Correct 32 ms 43684 KB Output is correct
48 Correct 26 ms 43748 KB Output is correct
49 Correct 29 ms 43832 KB Output is correct
50 Correct 25 ms 43604 KB Output is correct
51 Correct 26 ms 43540 KB Output is correct
52 Correct 25 ms 43604 KB Output is correct
53 Correct 25 ms 43576 KB Output is correct
54 Correct 25 ms 43600 KB Output is correct
55 Correct 26 ms 43624 KB Output is correct
56 Correct 22 ms 42708 KB Output is correct
57 Correct 21 ms 43444 KB Output is correct
58 Correct 28 ms 43604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 42580 KB Output is correct
2 Correct 20 ms 42692 KB Output is correct
3 Correct 21 ms 42728 KB Output is correct
4 Correct 435 ms 87252 KB Output is correct
5 Correct 346 ms 92212 KB Output is correct
6 Correct 467 ms 101860 KB Output is correct
7 Correct 618 ms 110752 KB Output is correct
8 Correct 606 ms 110508 KB Output is correct
9 Correct 586 ms 110656 KB Output is correct
10 Correct 581 ms 110672 KB Output is correct
11 Correct 598 ms 110592 KB Output is correct
12 Correct 393 ms 101480 KB Output is correct
13 Correct 406 ms 101456 KB Output is correct
14 Correct 401 ms 101388 KB Output is correct
15 Correct 97 ms 88464 KB Output is correct
16 Correct 608 ms 111740 KB Output is correct
17 Correct 91 ms 48584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 42580 KB Output is correct
2 Correct 422 ms 69020 KB Output is correct
3 Correct 707 ms 74312 KB Output is correct
4 Correct 547 ms 75308 KB Output is correct
5 Correct 972 ms 90768 KB Output is correct
6 Correct 892 ms 90920 KB Output is correct
7 Correct 900 ms 90900 KB Output is correct
8 Correct 888 ms 90692 KB Output is correct
9 Correct 940 ms 90880 KB Output is correct
10 Correct 925 ms 90896 KB Output is correct
11 Correct 894 ms 90864 KB Output is correct
12 Correct 886 ms 91216 KB Output is correct
13 Correct 885 ms 91412 KB Output is correct
14 Correct 934 ms 92576 KB Output is correct
15 Correct 1014 ms 97220 KB Output is correct
16 Correct 934 ms 91472 KB Output is correct
17 Correct 902 ms 91536 KB Output is correct
18 Correct 903 ms 91288 KB Output is correct
19 Correct 843 ms 95228 KB Output is correct
20 Correct 843 ms 95460 KB Output is correct
21 Correct 845 ms 95312 KB Output is correct
22 Correct 834 ms 95408 KB Output is correct
23 Correct 831 ms 95356 KB Output is correct
24 Correct 825 ms 95284 KB Output is correct
25 Correct 823 ms 95428 KB Output is correct
26 Correct 839 ms 95420 KB Output is correct
27 Correct 849 ms 95364 KB Output is correct
28 Correct 886 ms 95268 KB Output is correct
29 Correct 858 ms 95500 KB Output is correct
30 Correct 851 ms 95552 KB Output is correct
31 Correct 836 ms 95956 KB Output is correct
32 Correct 846 ms 96520 KB Output is correct
33 Correct 901 ms 98436 KB Output is correct
34 Correct 917 ms 102100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 42668 KB Output is correct
2 Correct 21 ms 42568 KB Output is correct
3 Correct 23 ms 42764 KB Output is correct
4 Correct 765 ms 77720 KB Output is correct
5 Correct 732 ms 78576 KB Output is correct
6 Correct 852 ms 89736 KB Output is correct
7 Correct 928 ms 95796 KB Output is correct
8 Correct 892 ms 95872 KB Output is correct
9 Correct 922 ms 95688 KB Output is correct
10 Correct 956 ms 95708 KB Output is correct
11 Correct 937 ms 95784 KB Output is correct
12 Correct 873 ms 95764 KB Output is correct
13 Correct 883 ms 95704 KB Output is correct
14 Correct 101 ms 48636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 42580 KB Output is correct
2 Correct 20 ms 42580 KB Output is correct
3 Correct 20 ms 42676 KB Output is correct
4 Correct 23 ms 42772 KB Output is correct
5 Correct 20 ms 42700 KB Output is correct
6 Correct 20 ms 42708 KB Output is correct
7 Correct 20 ms 42776 KB Output is correct
8 Correct 20 ms 42808 KB Output is correct
9 Correct 21 ms 42836 KB Output is correct
10 Correct 26 ms 42948 KB Output is correct
11 Correct 21 ms 42812 KB Output is correct
12 Correct 21 ms 42832 KB Output is correct
13 Correct 22 ms 42772 KB Output is correct
14 Correct 21 ms 42708 KB Output is correct
15 Correct 20 ms 42788 KB Output is correct
16 Correct 21 ms 42792 KB Output is correct
17 Correct 20 ms 42776 KB Output is correct
18 Correct 20 ms 42780 KB Output is correct
19 Correct 20 ms 42832 KB Output is correct
20 Correct 20 ms 42812 KB Output is correct
21 Correct 21 ms 42708 KB Output is correct
22 Correct 20 ms 42780 KB Output is correct
23 Correct 21 ms 42788 KB Output is correct
24 Correct 21 ms 42708 KB Output is correct
25 Correct 23 ms 42716 KB Output is correct
26 Correct 20 ms 42788 KB Output is correct
27 Correct 20 ms 42576 KB Output is correct
28 Correct 20 ms 42680 KB Output is correct
29 Correct 20 ms 42820 KB Output is correct
30 Correct 25 ms 43400 KB Output is correct
31 Correct 26 ms 43356 KB Output is correct
32 Correct 28 ms 43692 KB Output is correct
33 Correct 27 ms 43604 KB Output is correct
34 Correct 28 ms 43616 KB Output is correct
35 Correct 28 ms 43572 KB Output is correct
36 Correct 28 ms 43676 KB Output is correct
37 Correct 33 ms 43672 KB Output is correct
38 Correct 31 ms 43980 KB Output is correct
39 Correct 30 ms 43892 KB Output is correct
40 Correct 27 ms 43852 KB Output is correct
41 Correct 26 ms 43872 KB Output is correct
42 Correct 26 ms 43868 KB Output is correct
43 Correct 26 ms 43852 KB Output is correct
44 Correct 26 ms 43816 KB Output is correct
45 Correct 27 ms 43800 KB Output is correct
46 Correct 26 ms 43728 KB Output is correct
47 Correct 32 ms 43684 KB Output is correct
48 Correct 26 ms 43748 KB Output is correct
49 Correct 29 ms 43832 KB Output is correct
50 Correct 25 ms 43604 KB Output is correct
51 Correct 26 ms 43540 KB Output is correct
52 Correct 25 ms 43604 KB Output is correct
53 Correct 25 ms 43576 KB Output is correct
54 Correct 25 ms 43600 KB Output is correct
55 Correct 26 ms 43624 KB Output is correct
56 Correct 22 ms 42708 KB Output is correct
57 Correct 21 ms 43444 KB Output is correct
58 Correct 28 ms 43604 KB Output is correct
59 Correct 20 ms 42580 KB Output is correct
60 Correct 20 ms 42692 KB Output is correct
61 Correct 21 ms 42728 KB Output is correct
62 Correct 435 ms 87252 KB Output is correct
63 Correct 346 ms 92212 KB Output is correct
64 Correct 467 ms 101860 KB Output is correct
65 Correct 618 ms 110752 KB Output is correct
66 Correct 606 ms 110508 KB Output is correct
67 Correct 586 ms 110656 KB Output is correct
68 Correct 581 ms 110672 KB Output is correct
69 Correct 598 ms 110592 KB Output is correct
70 Correct 393 ms 101480 KB Output is correct
71 Correct 406 ms 101456 KB Output is correct
72 Correct 401 ms 101388 KB Output is correct
73 Correct 97 ms 88464 KB Output is correct
74 Correct 608 ms 111740 KB Output is correct
75 Correct 91 ms 48584 KB Output is correct
76 Correct 25 ms 42580 KB Output is correct
77 Correct 422 ms 69020 KB Output is correct
78 Correct 707 ms 74312 KB Output is correct
79 Correct 547 ms 75308 KB Output is correct
80 Correct 972 ms 90768 KB Output is correct
81 Correct 892 ms 90920 KB Output is correct
82 Correct 900 ms 90900 KB Output is correct
83 Correct 888 ms 90692 KB Output is correct
84 Correct 940 ms 90880 KB Output is correct
85 Correct 925 ms 90896 KB Output is correct
86 Correct 894 ms 90864 KB Output is correct
87 Correct 886 ms 91216 KB Output is correct
88 Correct 885 ms 91412 KB Output is correct
89 Correct 934 ms 92576 KB Output is correct
90 Correct 1014 ms 97220 KB Output is correct
91 Correct 934 ms 91472 KB Output is correct
92 Correct 902 ms 91536 KB Output is correct
93 Correct 903 ms 91288 KB Output is correct
94 Correct 843 ms 95228 KB Output is correct
95 Correct 843 ms 95460 KB Output is correct
96 Correct 845 ms 95312 KB Output is correct
97 Correct 834 ms 95408 KB Output is correct
98 Correct 831 ms 95356 KB Output is correct
99 Correct 825 ms 95284 KB Output is correct
100 Correct 823 ms 95428 KB Output is correct
101 Correct 839 ms 95420 KB Output is correct
102 Correct 849 ms 95364 KB Output is correct
103 Correct 886 ms 95268 KB Output is correct
104 Correct 858 ms 95500 KB Output is correct
105 Correct 851 ms 95552 KB Output is correct
106 Correct 836 ms 95956 KB Output is correct
107 Correct 846 ms 96520 KB Output is correct
108 Correct 901 ms 98436 KB Output is correct
109 Correct 917 ms 102100 KB Output is correct
110 Correct 21 ms 42668 KB Output is correct
111 Correct 21 ms 42568 KB Output is correct
112 Correct 23 ms 42764 KB Output is correct
113 Correct 765 ms 77720 KB Output is correct
114 Correct 732 ms 78576 KB Output is correct
115 Correct 852 ms 89736 KB Output is correct
116 Correct 928 ms 95796 KB Output is correct
117 Correct 892 ms 95872 KB Output is correct
118 Correct 922 ms 95688 KB Output is correct
119 Correct 956 ms 95708 KB Output is correct
120 Correct 937 ms 95784 KB Output is correct
121 Correct 873 ms 95764 KB Output is correct
122 Correct 883 ms 95704 KB Output is correct
123 Correct 101 ms 48636 KB Output is correct
124 Correct 787 ms 92136 KB Output is correct
125 Correct 603 ms 87804 KB Output is correct
126 Correct 945 ms 94252 KB Output is correct
127 Correct 934 ms 94236 KB Output is correct
128 Correct 965 ms 94248 KB Output is correct
129 Correct 974 ms 94344 KB Output is correct
130 Correct 919 ms 94216 KB Output is correct
131 Correct 743 ms 109492 KB Output is correct
132 Correct 724 ms 110532 KB Output is correct
133 Correct 732 ms 109432 KB Output is correct
134 Correct 866 ms 98864 KB Output is correct
135 Correct 866 ms 98864 KB Output is correct
136 Correct 939 ms 98796 KB Output is correct
137 Correct 683 ms 91452 KB Output is correct
138 Correct 664 ms 91336 KB Output is correct
139 Correct 666 ms 91428 KB Output is correct
140 Correct 673 ms 91604 KB Output is correct
141 Correct 653 ms 91372 KB Output is correct
142 Correct 676 ms 91476 KB Output is correct
143 Correct 109 ms 80700 KB Output is correct
144 Correct 935 ms 95476 KB Output is correct