# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47389 | mirbek01 | Construction of Highway (JOI18_construction) | C++17 | 1084 ms | 2804 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
int n, c[N], p[N], fen[N];
vector <int> vec;
void update(int pos, int val){
for(; pos <= n; pos |= pos + 1)
fen[pos] += val;
}
int get(int pos){
int res = 0;
for(; pos > 0; pos = (pos & (pos + 1)) - 1)
res += fen[pos];
return res;
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i ++){
scanf("%d", &c[i]);
vec.emplace_back(c[i]);
}
sort(vec.begin(), vec.end());
vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
for(int i = 1; i <= n; i ++){
c[i] = lower_bound(vec.begin(), vec.end(), c[i]) - vec.begin() + 1;
}
int cc = 0;
for(int i = 1; i < n; i ++){
int a, b;
scanf("%d %d", &a, &b);
int v = a, ans = 0;
set <int> st;
while(v){
update(c[v], 1);
ans += get(c[v] - 1);
st.insert(c[v]);
v = p[v];
}
cc += st.size();
v = a;
while(v){
update(c[v], -1);
c[v] = c[b];
v = p[v];
}
printf("%d\n", ans);
p[b] = a;
}
int lg = ceil(log2(n));
if(cc > n * max((lg - 2), 1)) assert(0);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |