제출 #1157692

#제출 시각아이디문제언어결과실행 시간메모리
115769212345678송신탑 (IOI22_towers)C++17
17 / 100
372 ms20260 KiB
#include "towers.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5;

int n, l[nx], r[nx], rt, dpt[nx], sm;
map<int, int> mp;
stack<int> s;
vector<int> h;
set<pair<int, int>> res;

void dfs(int u, int p)
{
    if (l[u]!=-1) dfs(l[u], u), dpt[u]=max(dpt[u], dpt[l[u]]+h[u]-h[l[u]]);
    if (r[u]!=-1) dfs(r[u], u), dpt[u]=max(dpt[u], dpt[r[u]]+h[u]-h[r[u]]);
    if (p!=-1) mp[dpt[u]+1]++, mp[dpt[u]+h[p]-h[u]+1]--;
}

void init(int N, std::vector<int> H) {
    h=H;
    for (int i=0; i<N; i++)
    {
        l[i]=r[i]=-1;
        while (!s.empty()&&H[s.top()]<H[i]) l[i]=s.top(), s.pop();
        if (s.empty()) rt=i;
        else r[s.top()]=i;
        s.push(i);
    }
    dfs(rt, -1);
    for (auto [x, y]:mp) sm+=y, res.insert({x, sm});
    //for (auto x:res) cout<<x.first<<' '<<x.second<<'\n';
}

int max_towers(int L, int R, int D) {
    if (prev(res.upper_bound({D, 1e9}))->second) return prev(res.upper_bound({D, 1e9}))->second;
    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...