답안 #705599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
705599 2023-03-04T18:30:51 Z danikoynov 송신탑 (IOI22_towers) C++17
37 / 100
4000 ms 72900 KB
#include "towers.h"

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;

int n, h[maxn], pref[maxn];
void init(int N, std::vector<int> H)
{
    n = N;
    for (int i = 0; i < n; i ++)
        h[i + 1] = H[i];

    for (int i = 2; i <= n; i ++)
    {
        pref[i] = pref[i - 1];
        if (h[i] > h[i - 1] && h[i] > h[i + 1])
            pref[i] ++;
    }
}

int par[maxn], rnk[maxn];

int find_leader(int v)
{
    return (v == par[v]) ? v : par[v] = find_leader(par[v]);
}

void unite(int v, int u)
{
    v = find_leader(v);
    u = find_leader(u);
    if (v == u)
        return;

    if (rnk[v] < rnk[u])
        swap(v, u);
    rnk[v] += rnk[u];
    par[u] = v;
}

int dp[maxn], bef[maxn], aft[maxn];

int tree[4 * maxn];

void update(int root, int left, int right, int pos, int val)
{
    if (left == right)
    {
        tree[root] = val;
        return;
    }

    int mid = (left + right) / 2;
    if (pos <= mid)
        update(root * 2, left, mid, pos, val);
    else
        update(root * 2 + 1, mid + 1, right, pos, val);

    tree[root] = max(tree[root * 2], tree[root * 2 + 1]);
}

int query(int root, int left, int right, int qleft, int qright)
{
    if (left > qright || right < qleft)
        return 0;

    if (left >= qleft && right <= qright)
        return tree[root];

    int mid = (left + right) / 2;
    return max(query(root * 2, left, mid, qleft, qright),
               query(root * 2 + 1, mid + 1, right, qleft, qright));
}

vector < int > act[maxn];
int max_towers(int L, int R, int D)
{

    L ++;
    R ++;

    if (D == 1)
    {
        int peaks = max(0, pref[R - 1] - pref[L]);
        return peaks + 1;
    }
    for (int i = 0; i < n; i ++)
        act[i].clear();
    for (int i = 0; i < 4 * n; i ++)
        tree[i] = 0;
    h[0] = h[n + 1] = 2e9;
    vector < int > st;
    st.push_back(0);
    for (int i = 1; i <= n; i ++)
    {
        int lf = 0, rf = st.size() - 1;
        while(lf <= rf)
        {
            int mf = (lf + rf) / 2;
            if (h[st[mf]] - D >= h[i])
                lf = mf + 1;
            else
                rf = mf - 1;
        }
        bef[i] = st[rf];

        while(!st.empty() && h[st.back()] <= h[i])
            st.pop_back();
        st.push_back(i);
    }

    st.clear();
    st.push_back(n + 1);
    for (int i = n; i > 0; i --)
    {
        int lf = 0, rf = st.size() - 1;
        while(lf <= rf)
        {
            int mf = (lf + rf) / 2;
            if (h[st[mf]] - D >= h[i])
                lf = mf + 1;
            else
                rf = mf - 1;
        }

        aft[i] = st[rf];

        while(!st.empty() && h[st.back()] <= h[i])
            st.pop_back();
        st.push_back(i);
    }

    int ans = 0;
    for (int i = L; i <= R; i ++)
    {
        for (int pos : act[i])
        {
            update(1, 0, n - 1, pos, dp[pos]);
        }
        act[i].clear();

        dp[i] = 1;
        int left = L, right = bef[i];
        if (left <= right)
        {
            int x = query(1, 0, n - 1, left, right) + 1;
            dp[i] = x;
        }

        act[aft[i]].push_back(i);

        ans = max(ans, dp[i]);
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4011 ms 72900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 3 ms 2768 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2768 KB Output is correct
5 Correct 2 ms 2768 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 3 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 3 ms 2588 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 2 ms 2768 KB Output is correct
27 Correct 2 ms 2768 KB Output is correct
28 Correct 2 ms 2664 KB Output is correct
29 Correct 2 ms 2768 KB Output is correct
30 Correct 2 ms 2768 KB Output is correct
31 Correct 3 ms 2768 KB Output is correct
32 Correct 3 ms 2768 KB Output is correct
33 Correct 2 ms 2768 KB Output is correct
34 Correct 2 ms 2768 KB Output is correct
35 Correct 2 ms 2768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 3 ms 2768 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2768 KB Output is correct
5 Correct 2 ms 2768 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 3 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 3 ms 2588 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 2 ms 2768 KB Output is correct
27 Correct 2 ms 2768 KB Output is correct
28 Correct 2 ms 2664 KB Output is correct
29 Correct 2 ms 2768 KB Output is correct
30 Correct 2 ms 2768 KB Output is correct
31 Correct 3 ms 2768 KB Output is correct
32 Correct 3 ms 2768 KB Output is correct
33 Correct 2 ms 2768 KB Output is correct
34 Correct 2 ms 2768 KB Output is correct
35 Correct 2 ms 2768 KB Output is correct
36 Correct 18 ms 5200 KB Output is correct
37 Correct 30 ms 6500 KB Output is correct
38 Correct 22 ms 6336 KB Output is correct
39 Correct 18 ms 6484 KB Output is correct
40 Correct 26 ms 6368 KB Output is correct
41 Correct 44 ms 7360 KB Output is correct
42 Correct 25 ms 6096 KB Output is correct
43 Correct 30 ms 7400 KB Output is correct
44 Correct 18 ms 7120 KB Output is correct
45 Correct 17 ms 6868 KB Output is correct
46 Correct 19 ms 6600 KB Output is correct
47 Correct 19 ms 4200 KB Output is correct
48 Correct 17 ms 4184 KB Output is correct
49 Correct 14 ms 4200 KB Output is correct
50 Correct 12 ms 4168 KB Output is correct
51 Correct 12 ms 4188 KB Output is correct
52 Correct 13 ms 4204 KB Output is correct
53 Correct 12 ms 4204 KB Output is correct
54 Correct 12 ms 4180 KB Output is correct
55 Correct 21 ms 4212 KB Output is correct
56 Correct 13 ms 4188 KB Output is correct
57 Correct 43 ms 7256 KB Output is correct
58 Correct 41 ms 7516 KB Output is correct
59 Correct 49 ms 7752 KB Output is correct
60 Correct 60 ms 8188 KB Output is correct
61 Correct 56 ms 8020 KB Output is correct
62 Correct 55 ms 7772 KB Output is correct
63 Correct 49 ms 8048 KB Output is correct
64 Correct 27 ms 8176 KB Output is correct
65 Correct 27 ms 7784 KB Output is correct
66 Correct 34 ms 7880 KB Output is correct
67 Correct 37 ms 7720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 551 ms 4188 KB Output is correct
2 Correct 702 ms 4204 KB Output is correct
3 Correct 677 ms 4192 KB Output is correct
4 Correct 1074 ms 4188 KB Output is correct
5 Correct 817 ms 4188 KB Output is correct
6 Correct 847 ms 4168 KB Output is correct
7 Correct 570 ms 4184 KB Output is correct
8 Correct 896 ms 4176 KB Output is correct
9 Correct 685 ms 4192 KB Output is correct
10 Correct 818 ms 4168 KB Output is correct
11 Correct 577 ms 4176 KB Output is correct
12 Correct 572 ms 4192 KB Output is correct
13 Correct 631 ms 4188 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 13 ms 4172 KB Output is correct
18 Correct 13 ms 4168 KB Output is correct
19 Correct 13 ms 4180 KB Output is correct
20 Correct 12 ms 4168 KB Output is correct
21 Correct 20 ms 4184 KB Output is correct
22 Correct 13 ms 4168 KB Output is correct
23 Correct 14 ms 4196 KB Output is correct
24 Correct 13 ms 4180 KB Output is correct
25 Correct 17 ms 4172 KB Output is correct
26 Correct 13 ms 4168 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 1 ms 2640 KB Output is correct
30 Correct 3 ms 2640 KB Output is correct
31 Correct 2 ms 2640 KB Output is correct
32 Correct 1 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2656 KB Output is correct
36 Correct 2 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4006 ms 69752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 3 ms 2768 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2768 KB Output is correct
5 Correct 2 ms 2768 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 3 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 3 ms 2588 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 2 ms 2768 KB Output is correct
27 Correct 2 ms 2768 KB Output is correct
28 Correct 2 ms 2664 KB Output is correct
29 Correct 2 ms 2768 KB Output is correct
30 Correct 2 ms 2768 KB Output is correct
31 Correct 3 ms 2768 KB Output is correct
32 Correct 3 ms 2768 KB Output is correct
33 Correct 2 ms 2768 KB Output is correct
34 Correct 2 ms 2768 KB Output is correct
35 Correct 2 ms 2768 KB Output is correct
36 Correct 18 ms 5200 KB Output is correct
37 Correct 30 ms 6500 KB Output is correct
38 Correct 22 ms 6336 KB Output is correct
39 Correct 18 ms 6484 KB Output is correct
40 Correct 26 ms 6368 KB Output is correct
41 Correct 44 ms 7360 KB Output is correct
42 Correct 25 ms 6096 KB Output is correct
43 Correct 30 ms 7400 KB Output is correct
44 Correct 18 ms 7120 KB Output is correct
45 Correct 17 ms 6868 KB Output is correct
46 Correct 19 ms 6600 KB Output is correct
47 Correct 19 ms 4200 KB Output is correct
48 Correct 17 ms 4184 KB Output is correct
49 Correct 14 ms 4200 KB Output is correct
50 Correct 12 ms 4168 KB Output is correct
51 Correct 12 ms 4188 KB Output is correct
52 Correct 13 ms 4204 KB Output is correct
53 Correct 12 ms 4204 KB Output is correct
54 Correct 12 ms 4180 KB Output is correct
55 Correct 21 ms 4212 KB Output is correct
56 Correct 13 ms 4188 KB Output is correct
57 Correct 43 ms 7256 KB Output is correct
58 Correct 41 ms 7516 KB Output is correct
59 Correct 49 ms 7752 KB Output is correct
60 Correct 60 ms 8188 KB Output is correct
61 Correct 56 ms 8020 KB Output is correct
62 Correct 55 ms 7772 KB Output is correct
63 Correct 49 ms 8048 KB Output is correct
64 Correct 27 ms 8176 KB Output is correct
65 Correct 27 ms 7784 KB Output is correct
66 Correct 34 ms 7880 KB Output is correct
67 Correct 37 ms 7720 KB Output is correct
68 Correct 551 ms 4188 KB Output is correct
69 Correct 702 ms 4204 KB Output is correct
70 Correct 677 ms 4192 KB Output is correct
71 Correct 1074 ms 4188 KB Output is correct
72 Correct 817 ms 4188 KB Output is correct
73 Correct 847 ms 4168 KB Output is correct
74 Correct 570 ms 4184 KB Output is correct
75 Correct 896 ms 4176 KB Output is correct
76 Correct 685 ms 4192 KB Output is correct
77 Correct 818 ms 4168 KB Output is correct
78 Correct 577 ms 4176 KB Output is correct
79 Correct 572 ms 4192 KB Output is correct
80 Correct 631 ms 4188 KB Output is correct
81 Correct 2 ms 2640 KB Output is correct
82 Correct 2 ms 2640 KB Output is correct
83 Correct 2 ms 2640 KB Output is correct
84 Correct 13 ms 4172 KB Output is correct
85 Correct 13 ms 4168 KB Output is correct
86 Correct 13 ms 4180 KB Output is correct
87 Correct 12 ms 4168 KB Output is correct
88 Correct 20 ms 4184 KB Output is correct
89 Correct 13 ms 4168 KB Output is correct
90 Correct 14 ms 4196 KB Output is correct
91 Correct 13 ms 4180 KB Output is correct
92 Correct 17 ms 4172 KB Output is correct
93 Correct 13 ms 4168 KB Output is correct
94 Correct 2 ms 2640 KB Output is correct
95 Correct 2 ms 2640 KB Output is correct
96 Correct 1 ms 2640 KB Output is correct
97 Correct 3 ms 2640 KB Output is correct
98 Correct 2 ms 2640 KB Output is correct
99 Correct 1 ms 2640 KB Output is correct
100 Correct 2 ms 2640 KB Output is correct
101 Correct 2 ms 2640 KB Output is correct
102 Correct 2 ms 2656 KB Output is correct
103 Correct 2 ms 2640 KB Output is correct
104 Execution timed out 4056 ms 15916 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4011 ms 72900 KB Time limit exceeded
2 Halted 0 ms 0 KB -