Submission #764239

# Submission time Handle Problem Language Result Execution time Memory
764239 2023-06-23T09:20:52 Z raysh07 Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 18388 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 69;
int a[maxn];
int n;
map <int, int> mp, inv;
vector <int> b;
int dp[maxn][2];
int seg[4 * maxn][2];

void upd(int l, int r, int pos, int qp, int v, int i){
    if (l == r){
        seg[pos][i] = v;
        return;
    }
    int mid = (l + r)/2;
    if (qp <= mid) upd(l, mid, pos*2, qp, v, i);
    else upd(mid + 1, r, pos*2 + 1, qp, v, i);
    
    seg[pos][i] = max(seg[pos * 2][i], seg[pos * 2 + 1][i]);
}

int query(int l, int r, int pos, int ql, int qr, int i){
    if (l >= ql && r <= qr) return seg[pos][i];
    else if (l > qr || r < ql) return 0;
    
    int mid = (l + r)/2;
    return max(query(l, mid, pos*2, ql, qr, i), query(mid + 1, r, pos*2 + 1, ql, qr, i));
}
 
void init(int N, vector<int> H) {
    n = N;
    for (int i = 0; i < N; i++){
        a[i + 1] = H[i];
    }
    
    set <int> st;
    for (int i = 1; i <= n; i++) st.insert(a[i]);
    int ptr = -1;
    st.insert(-1e9);
    st.insert(2e9 + 1);
    for (auto x : st){
        mp[x] = ++ptr;
        inv[ptr] = x;
        b.push_back(x);
    }
    
    for (int i = 1; i <= n; i++) {
        a[i] = mp[a[i]];
    }
}
 
int max_towers(int l, int r, int d) {
    l++;
    r++;
    int ans = 0;
    
    for (int i = l; i <= r; i++){
        int x = inv[a[i]];
        
        int pos = upper_bound(b.begin(), b.end(), x - d) - b.begin() - 1;
        dp[i][0] = query(1, n, 1, 1, pos, 0);
        upd(1, n, 1, a[i], dp[i][0], 1);
        
        pos = lower_bound(b.begin(), b.end(), x + d) - b.begin();
        dp[i][1] = 1 + query(1, n, 1, pos, n, 1);
        upd(1, n, 1, a[i], dp[i][1], 0);
        
        ans = max(ans, dp[i][0]);
        ans = max(ans, dp[i][1]);
    }
    
    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 11020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 632 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 3 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 592 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 632 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 3 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 592 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 71 ms 11396 KB Output is correct
37 Correct 129 ms 17872 KB Output is correct
38 Correct 112 ms 17692 KB Output is correct
39 Correct 120 ms 17764 KB Output is correct
40 Correct 106 ms 17720 KB Output is correct
41 Correct 165 ms 18204 KB Output is correct
42 Correct 111 ms 17624 KB Output is correct
43 Correct 92 ms 16952 KB Output is correct
44 Correct 68 ms 15928 KB Output is correct
45 Correct 66 ms 15836 KB Output is correct
46 Correct 61 ms 15912 KB Output is correct
47 Correct 128 ms 17816 KB Output is correct
48 Correct 112 ms 17780 KB Output is correct
49 Correct 95 ms 17664 KB Output is correct
50 Correct 77 ms 16184 KB Output is correct
51 Correct 86 ms 16676 KB Output is correct
52 Correct 220 ms 18328 KB Output is correct
53 Correct 193 ms 18384 KB Output is correct
54 Correct 196 ms 18280 KB Output is correct
55 Correct 140 ms 18344 KB Output is correct
56 Correct 130 ms 18384 KB Output is correct
57 Correct 167 ms 17776 KB Output is correct
58 Correct 187 ms 18384 KB Output is correct
59 Correct 192 ms 18320 KB Output is correct
60 Correct 215 ms 18324 KB Output is correct
61 Correct 193 ms 18388 KB Output is correct
62 Correct 200 ms 18388 KB Output is correct
63 Correct 202 ms 18384 KB Output is correct
64 Correct 107 ms 18360 KB Output is correct
65 Correct 112 ms 18312 KB Output is correct
66 Correct 112 ms 18376 KB Output is correct
67 Correct 144 ms 18360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4029 ms 18284 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 4648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 632 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 3 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 592 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 71 ms 11396 KB Output is correct
37 Correct 129 ms 17872 KB Output is correct
38 Correct 112 ms 17692 KB Output is correct
39 Correct 120 ms 17764 KB Output is correct
40 Correct 106 ms 17720 KB Output is correct
41 Correct 165 ms 18204 KB Output is correct
42 Correct 111 ms 17624 KB Output is correct
43 Correct 92 ms 16952 KB Output is correct
44 Correct 68 ms 15928 KB Output is correct
45 Correct 66 ms 15836 KB Output is correct
46 Correct 61 ms 15912 KB Output is correct
47 Correct 128 ms 17816 KB Output is correct
48 Correct 112 ms 17780 KB Output is correct
49 Correct 95 ms 17664 KB Output is correct
50 Correct 77 ms 16184 KB Output is correct
51 Correct 86 ms 16676 KB Output is correct
52 Correct 220 ms 18328 KB Output is correct
53 Correct 193 ms 18384 KB Output is correct
54 Correct 196 ms 18280 KB Output is correct
55 Correct 140 ms 18344 KB Output is correct
56 Correct 130 ms 18384 KB Output is correct
57 Correct 167 ms 17776 KB Output is correct
58 Correct 187 ms 18384 KB Output is correct
59 Correct 192 ms 18320 KB Output is correct
60 Correct 215 ms 18324 KB Output is correct
61 Correct 193 ms 18388 KB Output is correct
62 Correct 200 ms 18388 KB Output is correct
63 Correct 202 ms 18384 KB Output is correct
64 Correct 107 ms 18360 KB Output is correct
65 Correct 112 ms 18312 KB Output is correct
66 Correct 112 ms 18376 KB Output is correct
67 Correct 144 ms 18360 KB Output is correct
68 Execution timed out 4029 ms 18284 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 11020 KB Time limit exceeded
2 Halted 0 ms 0 KB -