# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
897707 | lovrot | Construction of Highway (JOI18_construction) | C++17 | 278 ms | 856 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
#include <algorithm>
#define EB emplace_back
using namespace std;
typedef long long ll;
const int LOG = 12;
const int N = 1 << LOG;
int n, C[N];
int F[N];
void add(int x, int val) {
for(++x; x < N; x += x & -x) F[x] += val;
}
int sum(int x) {
int sum = 0;
for(++x; x; x -= x & -x) sum += F[x];
return sum;
}
int P[N];
vector<int> S;
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d", C + i);
S.EB(C[i]);
}
sort(S.begin(), S.end());
S.erase(unique(S.begin(), S.end()), S.end());
for(int i = 0; i < n - 1; ++i) {
int a, b;
scanf("%d%d", &a, &b);
ll cost = 0;
for(int _a = a; _a; _a = P[_a]) {
int pos = lower_bound(S.begin(), S.end(), C[_a]) - S.begin() + 1;
cost += (ll) sum(pos - 1);
add(pos, 1);
}
printf("%lld\n", cost);
for(int _a = a; _a; _a = P[_a]) {
int pos = lower_bound(S.begin(), S.end(), C[_a]) - S.begin() + 1;
add(pos, -1);
C[_a] = C[b];
}
P[b] = a;
}
return 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... |