이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//~ #include "grader.cpp"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree <pair <int, int>, null_type, less <pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 1000001;
int n, c, r, mxd[N], can[N], d[N], sum[N], rightmost[N];
vector <int> v[N];
ordered_set invs;
map <pair <int, int>, int> mp;
int id(pair <int, int> p){
if(mp.find(p) == mp.end()){
int sz = mp.size();
mp[p] = sz;
}
return mp[p];
}
void dfs(int node, int pnode, int dep){
mxd[node] = d[node] = dep;
if(v[node].size() == 0){
can[node] = 1;
return;
}
for(auto &i : v[node]){
dfs(i, node, dep + 1);
mxd[node] = max(mxd[node], mxd[i]);
sum[node] += sum[i];
}
if(sum[node] == 0) can[node] = 1;
if(sum[node] == 1 && rightmost[v[node].back()]){
can[node] = 1;
rightmost[node] = 1;
}
}
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E){
n = N;
c = C;
r = R;
for(int i = 0 ; i < n ; i++){
invs.insert({i, i});
id({i, i});
}
for(int i = 0 ; i < c ; i++){
int l = S[i], r = E[i];
assert(r < (int)invs.size());
vector <pair <int, int> > children;
for(int j = 0 ; j < r - l + 1 ; j++){
auto it = invs.find_by_order(l);
children.push_back(*it);
invs.erase(it);
}
l = children[0].first;
r = children.back().second;
for(auto &i : children){
v[id({l, r})].push_back(id(i));
}
invs.insert({l, r});
}
for(int i = 0 ; i < n - 1 ; i++){
if(K[i] > R){
sum[id({i, i})] = rightmost[id({i, i})] = 1;
}
}
int root = id({0, n - 1});
dfs(root, -1, 0);
int ans = 0;
for(int node = 0 ; node < (int)mp.size() ; node++){
if(can[node]){
ans = max(ans, mxd[node] - d[node]);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |