답안 #830961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
830961 2023-08-19T13:41:33 Z Wael 송신탑 (IOI22_towers) C++17
0 / 100
2270 ms 617000 KB
#include <bits/stdc++.h>
using namespace std;
#include "towers.h"
typedef int ll;
int const M = 4e5 + 10 , lg = 32 , Size = M * lg;
int n , s[M] , dp[M];

void init(int N, vector<ll> H) {
    n = N;
    for(int i = 1 ; i <= n ; ++i) s[i] = H[i - 1];
}

struct sgtree {

    int cur = 1 , type;
    int Left[Size] , Right[Size] , mx[Size];

    void Init(int t) {
        type = t;
        for(int i = 0 ; i < Size ; ++i) Left[i] = Right[i] = mx[i] = 0;
    }

    inline void UpdateRange(int l , int r , int val , int node = 1 , int lx = 1 , int rx = 1e9) {
        if(lx > r || rx < l) return;
        if(lx >= l && rx <= r) {
            mx[node] = max(mx[node] , val);
            return;
        }
        int mid = (lx + rx) / 2;
        if(Left[node] == 0) Left[node] = ++cur;
        if(Right[node] == 0) Right[node] = ++cur;
        Update(l , r , val , Left[node] , lx , mid);
        Update(l , r , val , Right[node] , mid + 1 , rx);
    }

    inline void Update(int l , int r , int val , int node = 1 , int lx = 1 , int rx = 1e9) {
        if(lx > r || rx < l) return;
        if(lx >= l && rx <= r) {
            mx[node] = max(mx[node] , val);
            return;
        }
        int mid = (lx + rx) / 2;
        if(Left[node] == 0) Left[node] = ++cur;
        if(Right[node] == 0) Right[node] = ++cur;
        Update(l , r , val , Left[node] , lx , mid);
        Update(l , r , val , Right[node] , mid + 1 , rx);
        mx[node] = max(mx[Left[node]] , mx[Right[node]]);
    }

    inline ll GetMax(int l , int r , int node = 1 , int lx = 1 , int rx = 1e9) {
        if(lx > r || rx < l || node == 0) return 0;
        if(lx >= l && rx <= r) return mx[node];
        int mid = (lx + rx) / 2;
        int res = max(GetMax(l , r , Left[node] , lx , mid) , GetMax(l , r , Right[node] , mid + 1 , rx));
        if(type == 1) res = max(res , mx[node]);
        return res;
    }

} Tree[2];

int max_towers(int L, int R, int D) {
    Tree[0].Init(0);
    Tree[1].Init(1);
    ++L , ++R;
    int ans = 1;
    for(int i = L ; i <= R ; ++i) {
        dp[i] = 1 + Tree[1].GetMax(s[i] , s[i]);
        if(s[i] - D >= 1) {
            int MaxLeft = Tree[0].GetMax(1 , s[i] - D);
            //cout << "i = " << i << " MaxLeft = " << MaxLeft << endl;
            Tree[1].UpdateRange(1 , s[i] - D , MaxLeft);
        }
        Tree[0].Update(s[i] , s[i] , dp[i]);
        ans = max(ans , dp[i]);
        //cout << "i = " << i << " " << dp[i] << endl;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2270 ms 616632 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 90 ms 300876 KB 1st lines differ - on the 1st token, expected: '13', found: '15'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 90 ms 300876 KB 1st lines differ - on the 1st token, expected: '13', found: '15'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1362 ms 617000 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1946 ms 616528 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 90 ms 300876 KB 1st lines differ - on the 1st token, expected: '13', found: '15'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2270 ms 616632 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -