Submission #830957

# Submission time Handle Problem Language Result Execution time Memory
830957 2023-08-19T13:39:05 Z Wael Radio Towers (IOI22_towers) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#include "towers.h"
typedef int ll;
int const M = 1e5 + 10 , lg = 31 , 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 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].Update(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 |     }
      |     ^