답안 #705601

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

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

int n, h[maxn], pref[maxn], peak_pos;
int cnt = 0;
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 = 1; i <= n; i ++)
                    if (h[i] > h[i - 1] && h[i] > h[i + 1])
                    cnt ++;
    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] ++, peak_pos = 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 (cnt == 1)
    {
        if (peak_pos <= L || peak_pos >= R)
            return 1;
        if (h[L] <= h[peak_pos] - D && h[R] <= h[peak_pos] - D)
            return 2;
        return 1;
    }
    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;
}

Compilation message

towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:12:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   12 |     for (int i = 0; i < n; i ++)
      |     ^~~
towers.cpp:15:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   15 |         for (int i = 1; i <= n; i ++)
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 3536 KB Output is correct
2 Correct 802 ms 4176 KB Output is correct
3 Correct 726 ms 4176 KB Output is correct
4 Correct 807 ms 4184 KB Output is correct
5 Correct 748 ms 4188 KB Output is correct
6 Correct 704 ms 4168 KB Output is correct
7 Correct 841 ms 4188 KB Output is correct
8 Correct 1 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2640 KB Output is correct
2 Correct 2 ms 2768 KB Output is correct
3 Correct 2 ms 2768 KB Output is correct
4 Correct 2 ms 2640 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 2768 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 2768 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 1 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 1 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 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 3 ms 2640 KB Output is correct
25 Correct 2 ms 2600 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 2768 KB Output is correct
29 Correct 2 ms 2768 KB Output is correct
30 Correct 3 ms 2768 KB Output is correct
31 Correct 2 ms 2768 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 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 3 ms 2640 KB Output is correct
2 Correct 2 ms 2768 KB Output is correct
3 Correct 2 ms 2768 KB Output is correct
4 Correct 2 ms 2640 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 2768 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 2768 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 1 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 1 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 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 3 ms 2640 KB Output is correct
25 Correct 2 ms 2600 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 2768 KB Output is correct
29 Correct 2 ms 2768 KB Output is correct
30 Correct 3 ms 2768 KB Output is correct
31 Correct 2 ms 2768 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 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 5228 KB Output is correct
37 Correct 22 ms 6476 KB Output is correct
38 Correct 22 ms 6372 KB Output is correct
39 Correct 22 ms 6496 KB Output is correct
40 Correct 22 ms 6340 KB Output is correct
41 Correct 41 ms 7376 KB Output is correct
42 Correct 16 ms 6228 KB Output is correct
43 Correct 20 ms 4184 KB Output is correct
44 Correct 20 ms 4168 KB Output is correct
45 Correct 24 ms 6848 KB Output is correct
46 Correct 17 ms 6628 KB Output is correct
47 Correct 13 ms 4168 KB Output is correct
48 Correct 13 ms 4192 KB Output is correct
49 Correct 20 ms 4188 KB Output is correct
50 Correct 19 ms 4168 KB Output is correct
51 Correct 21 ms 4192 KB Output is correct
52 Correct 12 ms 4212 KB Output is correct
53 Correct 12 ms 4176 KB Output is correct
54 Correct 13 ms 4188 KB Output is correct
55 Correct 16 ms 4188 KB Output is correct
56 Correct 11 ms 4200 KB Output is correct
57 Correct 34 ms 7116 KB Output is correct
58 Correct 43 ms 7504 KB Output is correct
59 Correct 47 ms 7696 KB Output is correct
60 Correct 57 ms 8124 KB Output is correct
61 Correct 49 ms 8012 KB Output is correct
62 Correct 39 ms 7768 KB Output is correct
63 Correct 46 ms 8020 KB Output is correct
64 Correct 12 ms 4192 KB Output is correct
65 Correct 12 ms 4196 KB Output is correct
66 Correct 33 ms 7836 KB Output is correct
67 Correct 40 ms 7764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 618 ms 4188 KB Output is correct
2 Correct 809 ms 4176 KB Output is correct
3 Correct 809 ms 4196 KB Output is correct
4 Correct 901 ms 4184 KB Output is correct
5 Correct 682 ms 4180 KB Output is correct
6 Correct 548 ms 4184 KB Output is correct
7 Correct 646 ms 4196 KB Output is correct
8 Correct 831 ms 4180 KB Output is correct
9 Correct 853 ms 4176 KB Output is correct
10 Correct 809 ms 4200 KB Output is correct
11 Correct 908 ms 4176 KB Output is correct
12 Correct 859 ms 4200 KB Output is correct
13 Correct 831 ms 4180 KB Output is correct
14 Correct 1 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 14 ms 4188 KB Output is correct
18 Correct 14 ms 4196 KB Output is correct
19 Correct 12 ms 4184 KB Output is correct
20 Correct 12 ms 4192 KB Output is correct
21 Correct 12 ms 4192 KB Output is correct
22 Correct 13 ms 4176 KB Output is correct
23 Correct 12 ms 4180 KB Output is correct
24 Correct 12 ms 4196 KB Output is correct
25 Correct 12 ms 4180 KB Output is correct
26 Correct 14 ms 4320 KB Output is correct
27 Correct 3 ms 2640 KB Output is correct
28 Correct 1 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 1 ms 2640 KB Output is correct
31 Correct 2 ms 2640 KB Output is correct
32 Correct 2 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 3 ms 2660 KB Output is correct
36 Correct 2 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4090 ms 69876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2640 KB Output is correct
2 Correct 2 ms 2768 KB Output is correct
3 Correct 2 ms 2768 KB Output is correct
4 Correct 2 ms 2640 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 2768 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 2768 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 1 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 1 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 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 3 ms 2640 KB Output is correct
25 Correct 2 ms 2600 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 2768 KB Output is correct
29 Correct 2 ms 2768 KB Output is correct
30 Correct 3 ms 2768 KB Output is correct
31 Correct 2 ms 2768 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 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 5228 KB Output is correct
37 Correct 22 ms 6476 KB Output is correct
38 Correct 22 ms 6372 KB Output is correct
39 Correct 22 ms 6496 KB Output is correct
40 Correct 22 ms 6340 KB Output is correct
41 Correct 41 ms 7376 KB Output is correct
42 Correct 16 ms 6228 KB Output is correct
43 Correct 20 ms 4184 KB Output is correct
44 Correct 20 ms 4168 KB Output is correct
45 Correct 24 ms 6848 KB Output is correct
46 Correct 17 ms 6628 KB Output is correct
47 Correct 13 ms 4168 KB Output is correct
48 Correct 13 ms 4192 KB Output is correct
49 Correct 20 ms 4188 KB Output is correct
50 Correct 19 ms 4168 KB Output is correct
51 Correct 21 ms 4192 KB Output is correct
52 Correct 12 ms 4212 KB Output is correct
53 Correct 12 ms 4176 KB Output is correct
54 Correct 13 ms 4188 KB Output is correct
55 Correct 16 ms 4188 KB Output is correct
56 Correct 11 ms 4200 KB Output is correct
57 Correct 34 ms 7116 KB Output is correct
58 Correct 43 ms 7504 KB Output is correct
59 Correct 47 ms 7696 KB Output is correct
60 Correct 57 ms 8124 KB Output is correct
61 Correct 49 ms 8012 KB Output is correct
62 Correct 39 ms 7768 KB Output is correct
63 Correct 46 ms 8020 KB Output is correct
64 Correct 12 ms 4192 KB Output is correct
65 Correct 12 ms 4196 KB Output is correct
66 Correct 33 ms 7836 KB Output is correct
67 Correct 40 ms 7764 KB Output is correct
68 Correct 618 ms 4188 KB Output is correct
69 Correct 809 ms 4176 KB Output is correct
70 Correct 809 ms 4196 KB Output is correct
71 Correct 901 ms 4184 KB Output is correct
72 Correct 682 ms 4180 KB Output is correct
73 Correct 548 ms 4184 KB Output is correct
74 Correct 646 ms 4196 KB Output is correct
75 Correct 831 ms 4180 KB Output is correct
76 Correct 853 ms 4176 KB Output is correct
77 Correct 809 ms 4200 KB Output is correct
78 Correct 908 ms 4176 KB Output is correct
79 Correct 859 ms 4200 KB Output is correct
80 Correct 831 ms 4180 KB Output is correct
81 Correct 1 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 14 ms 4188 KB Output is correct
85 Correct 14 ms 4196 KB Output is correct
86 Correct 12 ms 4184 KB Output is correct
87 Correct 12 ms 4192 KB Output is correct
88 Correct 12 ms 4192 KB Output is correct
89 Correct 13 ms 4176 KB Output is correct
90 Correct 12 ms 4180 KB Output is correct
91 Correct 12 ms 4196 KB Output is correct
92 Correct 12 ms 4180 KB Output is correct
93 Correct 14 ms 4320 KB Output is correct
94 Correct 3 ms 2640 KB Output is correct
95 Correct 1 ms 2640 KB Output is correct
96 Correct 2 ms 2640 KB Output is correct
97 Correct 1 ms 2640 KB Output is correct
98 Correct 2 ms 2640 KB Output is correct
99 Correct 2 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 3 ms 2660 KB Output is correct
103 Correct 2 ms 2640 KB Output is correct
104 Execution timed out 4080 ms 15936 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 3536 KB Output is correct
2 Correct 802 ms 4176 KB Output is correct
3 Correct 726 ms 4176 KB Output is correct
4 Correct 807 ms 4184 KB Output is correct
5 Correct 748 ms 4188 KB Output is correct
6 Correct 704 ms 4168 KB Output is correct
7 Correct 841 ms 4188 KB Output is correct
8 Correct 1 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 2768 KB Output is correct
13 Correct 2 ms 2768 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2768 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2768 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 2768 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 1 ms 2640 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 2640 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 2 ms 2640 KB Output is correct
31 Correct 2 ms 2640 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 3 ms 2640 KB Output is correct
35 Correct 2 ms 2600 KB Output is correct
36 Correct 2 ms 2768 KB Output is correct
37 Correct 2 ms 2768 KB Output is correct
38 Correct 2 ms 2768 KB Output is correct
39 Correct 2 ms 2768 KB Output is correct
40 Correct 3 ms 2768 KB Output is correct
41 Correct 2 ms 2768 KB Output is correct
42 Correct 2 ms 2640 KB Output is correct
43 Correct 2 ms 2640 KB Output is correct
44 Correct 2 ms 2768 KB Output is correct
45 Correct 2 ms 2768 KB Output is correct
46 Correct 18 ms 5228 KB Output is correct
47 Correct 22 ms 6476 KB Output is correct
48 Correct 22 ms 6372 KB Output is correct
49 Correct 22 ms 6496 KB Output is correct
50 Correct 22 ms 6340 KB Output is correct
51 Correct 41 ms 7376 KB Output is correct
52 Correct 16 ms 6228 KB Output is correct
53 Correct 20 ms 4184 KB Output is correct
54 Correct 20 ms 4168 KB Output is correct
55 Correct 24 ms 6848 KB Output is correct
56 Correct 17 ms 6628 KB Output is correct
57 Correct 13 ms 4168 KB Output is correct
58 Correct 13 ms 4192 KB Output is correct
59 Correct 20 ms 4188 KB Output is correct
60 Correct 19 ms 4168 KB Output is correct
61 Correct 21 ms 4192 KB Output is correct
62 Correct 12 ms 4212 KB Output is correct
63 Correct 12 ms 4176 KB Output is correct
64 Correct 13 ms 4188 KB Output is correct
65 Correct 16 ms 4188 KB Output is correct
66 Correct 11 ms 4200 KB Output is correct
67 Correct 34 ms 7116 KB Output is correct
68 Correct 43 ms 7504 KB Output is correct
69 Correct 47 ms 7696 KB Output is correct
70 Correct 57 ms 8124 KB Output is correct
71 Correct 49 ms 8012 KB Output is correct
72 Correct 39 ms 7768 KB Output is correct
73 Correct 46 ms 8020 KB Output is correct
74 Correct 12 ms 4192 KB Output is correct
75 Correct 12 ms 4196 KB Output is correct
76 Correct 33 ms 7836 KB Output is correct
77 Correct 40 ms 7764 KB Output is correct
78 Correct 618 ms 4188 KB Output is correct
79 Correct 809 ms 4176 KB Output is correct
80 Correct 809 ms 4196 KB Output is correct
81 Correct 901 ms 4184 KB Output is correct
82 Correct 682 ms 4180 KB Output is correct
83 Correct 548 ms 4184 KB Output is correct
84 Correct 646 ms 4196 KB Output is correct
85 Correct 831 ms 4180 KB Output is correct
86 Correct 853 ms 4176 KB Output is correct
87 Correct 809 ms 4200 KB Output is correct
88 Correct 908 ms 4176 KB Output is correct
89 Correct 859 ms 4200 KB Output is correct
90 Correct 831 ms 4180 KB Output is correct
91 Correct 1 ms 2640 KB Output is correct
92 Correct 2 ms 2640 KB Output is correct
93 Correct 2 ms 2640 KB Output is correct
94 Correct 14 ms 4188 KB Output is correct
95 Correct 14 ms 4196 KB Output is correct
96 Correct 12 ms 4184 KB Output is correct
97 Correct 12 ms 4192 KB Output is correct
98 Correct 12 ms 4192 KB Output is correct
99 Correct 13 ms 4176 KB Output is correct
100 Correct 12 ms 4180 KB Output is correct
101 Correct 12 ms 4196 KB Output is correct
102 Correct 12 ms 4180 KB Output is correct
103 Correct 14 ms 4320 KB Output is correct
104 Correct 3 ms 2640 KB Output is correct
105 Correct 1 ms 2640 KB Output is correct
106 Correct 2 ms 2640 KB Output is correct
107 Correct 1 ms 2640 KB Output is correct
108 Correct 2 ms 2640 KB Output is correct
109 Correct 2 ms 2640 KB Output is correct
110 Correct 2 ms 2640 KB Output is correct
111 Correct 2 ms 2640 KB Output is correct
112 Correct 3 ms 2660 KB Output is correct
113 Correct 2 ms 2640 KB Output is correct
114 Execution timed out 4090 ms 69876 KB Time limit exceeded
115 Halted 0 ms 0 KB -