답안 #830955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
830955 2023-08-19T13:36:49 Z Wael 송신탑 (IOI22_towers) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#include "towers.h"
typedef int ll;
int const M = 1e5 + 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];

    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;
}

Compilation message

towers.cpp:18:5: error: ISO C++ forbids declaration of 'init' with no type [-fpermissive]
   18 |     init(int t) {
      |     ^~~~
towers.cpp: In member function 'int sgtree::init(int)':
towers.cpp:21:5: warning: no return statement in function returning non-void [-Wreturn-type]
   21 |     }
      |     ^