답안 #633419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
633419 2022-08-22T12:18:36 Z Lawliet 송신탑 (IOI22_towers) C++17
18 / 100
966 ms 8096 KB
#include "towers.h"
#include <bits/stdc++.h>

using namespace std;

const int maxl = 20;
const int maxn = 100010;
const int inf = 1000000010;

class SparseTable
{
    public:

        void build(int n, vector<int> v)
        {
            for(int i = 1 ; i <= n ; i++)
                tab[0][i] = v[i];

            for(int k = 1 ; k < maxl ; k++)
                for(int i = 1 ; i + (1 << k) - 1 <= n ; i++)
                    tab[k][i] = max( tab[k - 1][i] , tab[k - 1][i + (1 << (k - 1))] ); 
        }

        int query(int l, int r)
        {
            if( l > r )
                return -inf;

            int t = 31 - __builtin_clz(r - l + 1);
            return max( tab[t][l] , tab[t][r - (1 << t) + 1] );
        }

    protected:

        int tab[maxl][maxn];
};

int n;

int v[maxn];
int dp[maxn];

bool hasBuilt = false;

SparseTable st;

vector<int> valleys;

bool isValid(int i, int j, int D)
{
    int peak = st.query( i + 1 , j - 1 );

    if( v[i] <= peak - D && v[j] <= peak - D )
        return true;

    return false;
}

void build(int D)
{
    for(int i = 1 ; i <= n ; i++)
    {
        while( !valleys.empty() )
        {
            int j = valleys.back();

            if( isValid( j , i , D ) )
            {
                valleys.push_back( i );
                break;
            }

            if( v[j] < v[i] )
                break;

            valleys.pop_back();
        }

        if( valleys.empty() )
            valleys.push_back( i );
    }

    hasBuilt = true;
}

void init(int N, vector<int> H) {
    n = N;

    H.insert( H.begin() , 0 );

    for(int i = 1 ; i <= n ; i++)
        v[i] = H[i];

    st.build( n , H );
}

int max_towers(int L, int R, int D) 
{
    if( !hasBuilt )
        build( D );

    L++; R++;

    if( R - L + 1 <= 2 )
        return 1;

    int pL = lower_bound( valleys.begin() , valleys.end() , L ) - valleys.begin();
    int pR = upper_bound( valleys.begin() , valleys.end() , R ) - valleys.begin();

    if( pL == pR )
    {
        if( isValid( L , R , D ) )
            return 2;

        return 1;
    }

    int ans = pR - pL;

    if( isValid( L , valleys[pL] , D ) )
        ans++;

    if( isValid( valleys[pR - 1] , R , D ) )
        ans++;

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 4708 KB Output is correct
2 Correct 807 ms 8008 KB Output is correct
3 Correct 719 ms 7996 KB Output is correct
4 Correct 740 ms 7972 KB Output is correct
5 Correct 774 ms 8008 KB Output is correct
6 Correct 806 ms 7972 KB Output is correct
7 Correct 842 ms 7960 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Incorrect 1 ms 464 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Incorrect 1 ms 464 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 736 ms 8012 KB Output is correct
2 Correct 925 ms 7956 KB Output is correct
3 Correct 886 ms 8000 KB Output is correct
4 Correct 966 ms 8000 KB Output is correct
5 Correct 799 ms 7984 KB Output is correct
6 Correct 881 ms 7956 KB Output is correct
7 Correct 774 ms 7968 KB Output is correct
8 Correct 686 ms 8008 KB Output is correct
9 Correct 875 ms 8000 KB Output is correct
10 Correct 782 ms 7992 KB Output is correct
11 Correct 772 ms 8096 KB Output is correct
12 Correct 902 ms 7972 KB Output is correct
13 Correct 817 ms 7960 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 23 ms 7972 KB Output is correct
18 Correct 16 ms 7960 KB Output is correct
19 Correct 24 ms 7960 KB Output is correct
20 Correct 25 ms 8000 KB Output is correct
21 Correct 17 ms 7960 KB Output is correct
22 Correct 16 ms 7972 KB Output is correct
23 Correct 15 ms 7984 KB Output is correct
24 Correct 15 ms 7976 KB Output is correct
25 Correct 15 ms 7972 KB Output is correct
26 Correct 15 ms 7960 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 299 ms 2000 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Incorrect 1 ms 464 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 4708 KB Output is correct
2 Correct 807 ms 8008 KB Output is correct
3 Correct 719 ms 7996 KB Output is correct
4 Correct 740 ms 7972 KB Output is correct
5 Correct 774 ms 8008 KB Output is correct
6 Correct 806 ms 7972 KB Output is correct
7 Correct 842 ms 7960 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Incorrect 1 ms 464 KB 1st lines differ - on the 1st token, expected: '34', found: '33'
18 Halted 0 ms 0 KB -