Submission #1070655

# Submission time Handle Problem Language Result Execution time Memory
1070655 2024-08-22T16:28:49 Z Boas Radio Towers (IOI22_towers) C++17
14 / 100
4000 ms 14344 KB
#include "towers.h"

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

template <typename T1, typename T2>
using indexed_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_set = indexed_map<T, null_type>;

#define loop(x, i) for (int i = 0; i < (x); i++)
#define loop1(x, i) for (int i = 1; i <= (x); i++)
#define rev(x, i) for (int i = (int)(x) - 1; i >= 0; i--)
#define itloop(x) for (auto it = begin(x); x != end(x); it++)
#define itrev(x) for (auto it = rbegin(x); x != rend(x); it++)
#define INF ((int64_t)(4e18 + 1))
#define INF32 ((int32_t)(2e9 + 1))
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define removeIn(x, l) l.erase(find(ALL(l), x))
#define pb push_back
#define sz(x) (int)(x).size()
#define F first
#define S second
#define var const auto &
#define foreach(l) for (var e : l)

typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;
typedef vector<viii> vviii;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;
typedef vector<si> vsi;
typedef vector<sii> vsii;
typedef vector<vsi> vvsi;
typedef vector<string> vstr;
typedef vector<vector<string>> vvstr;
typedef vector<bool> vb;
typedef vector<vb> vvb;

vi h;
vii minTree, maxTree;
vi dp, maxDP;
vvi p;
int n;
int treeN = 1;
int lastD = -1;

void init(int N, vi H)
{
    h = H;
    n = N;
    while (treeN < N)
        treeN *= 2;
    minTree = vii(treeN * 2, {1e9, 1e9});
    maxTree = vii(treeN * 2, {0, -1e9});
    loop(n, i)
    {
        minTree[treeN + i] = {H[i], i};
        maxTree[treeN + i] = {H[i], -i};
    }
    rev(treeN, i)
    {
        minTree[i] = min(minTree[2 * i + 1], minTree[2 * i]);
        maxTree[i] = max(maxTree[2 * i + 1], maxTree[2 * i]);
    }
}

ii combine(ii a, ii b, bool minOp)
{
    if (minOp)
        return min(a, b);
    return max(a, b);
}

// v, ix
ii query(int i, int l, int r, int ql, int qr, bool minOp)
{
    if (r < ql || qr < l)
        return {1e9 * minOp, 1e9 * minOp};
    int m = l + (r - l) / 2;
    if (ql <= l && r <= qr)
    {
        if (minOp)
            return minTree[i];
        return maxTree[i];
    }
    return combine(query(2 * i, l, m, ql, qr, minOp),
                   query(2 * i + 1, m + 1, r, ql, qr, minOp), minOp);
}

void calcDP(int D)
{
    lastD = D;
    dp = maxDP = vi(n + 1, 1);
    p = vvi(20, vi(n + 1));
    for (int i = n - 2; i >= 0; i--)
    {
        int lo = i + 2, hi = n;
        bool suc = 0;
        int lastIx = -1;
        while (hi >= lo)
        {
            int m = lo + (hi - lo) / 2;
            if (i + 1 > m - 1)
            {
                lo = m + 1;
                continue;
            }
            auto [mn, mnIx] = query(1, 0, treeN - 1, i + 2, m, 1);
            auto [mx, mxIx] = query(1, 0, treeN - 1, i + 1, mnIx - 1, 0);
            mxIx *= -1;
            if (mx - max(mn, h[i]) >= D)
            {
                lastIx = mnIx;
                suc = 1;
                if (lo == hi)
                    break;
                hi = m;
            }
            else
            {
                lo = m + 1;
            }
        }
        if (suc)
        {
            p[0][i] = lastIx;
            dp[i] = maxDP[lastIx] + 1;
        }
        else
            p[0][i] = i;
        maxDP[i] = max(dp[i], maxDP[i + 1]);
    }
    loop1(19, x)
    {
        loop(n, i)
        {
            p[x][i] = p[x - 1][p[x - 1][i]];
        }
    }
}

int getParent(int i, int k)
{
    loop(20, x)
    {
        if ((1 << x) & k)
        {
            i = p[x][i];
        }
    }
    return i;
}

int max_towers(int L, int R, int D)
{
    if (lastD != D)
    {
        calcDP(D);
    }
    return max(maxDP[L] - maxDP[R - 1] + 1, 1);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4054 ms 13412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Incorrect 7 ms 600 KB 1st lines differ - on the 1st token, expected: '91', found: '92'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Incorrect 7 ms 600 KB 1st lines differ - on the 1st token, expected: '91', found: '92'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1114 ms 14344 KB Output is correct
2 Correct 1273 ms 14312 KB Output is correct
3 Correct 1220 ms 14308 KB Output is correct
4 Correct 1206 ms 14288 KB Output is correct
5 Correct 1285 ms 14288 KB Output is correct
6 Correct 1253 ms 14288 KB Output is correct
7 Correct 1257 ms 14288 KB Output is correct
8 Correct 1214 ms 14312 KB Output is correct
9 Correct 1434 ms 14308 KB Output is correct
10 Correct 1262 ms 14288 KB Output is correct
11 Correct 1448 ms 14288 KB Output is correct
12 Correct 1340 ms 14288 KB Output is correct
13 Correct 1354 ms 14288 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 6 ms 600 KB Output is correct
16 Correct 6 ms 684 KB Output is correct
17 Correct 622 ms 14304 KB Output is correct
18 Correct 607 ms 14288 KB Output is correct
19 Correct 626 ms 14288 KB Output is correct
20 Correct 725 ms 14312 KB Output is correct
21 Correct 588 ms 14312 KB Output is correct
22 Correct 616 ms 14312 KB Output is correct
23 Correct 615 ms 14288 KB Output is correct
24 Correct 630 ms 14100 KB Output is correct
25 Correct 769 ms 14288 KB Output is correct
26 Correct 645 ms 14288 KB Output is correct
27 Correct 6 ms 600 KB Output is correct
28 Correct 6 ms 600 KB Output is correct
29 Correct 5 ms 600 KB Output is correct
30 Correct 6 ms 600 KB Output is correct
31 Correct 5 ms 600 KB Output is correct
32 Correct 6 ms 688 KB Output is correct
33 Correct 6 ms 600 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 6 ms 600 KB Output is correct
36 Correct 5 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4051 ms 5752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Incorrect 7 ms 600 KB 1st lines differ - on the 1st token, expected: '91', found: '92'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4054 ms 13412 KB Time limit exceeded
2 Halted 0 ms 0 KB -