| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 47381 | Talant | Construction of Highway (JOI18_construction) | C++17 | 271 ms | 972 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define int long long
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)4200;
int n;
int c[N];
int a,b;
int pr[N];
int t[N];
vector <int> vec;
void upd (int x) {
for (; x < N; x += (x & -x))
t[x] ++;
}
int get (int x) {
int res = 0;
for (; x > 0; x -= (x & -x)) {
res += t[x];
}
return res;
}
main () {
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> c[i];
vec.pb(c[i]);
}
sort (all(vec));
vec.erase (unique(all(vec)),vec.end());
for (int i = 1; i <= n; i ++)
c[i] = lower_bound(all(vec),c[i]) - vec.begin() + 2;
int q = n - 1;
pr[1] = -1;
while (q --) {
scanf ("%lld%lld", &a,&b);
int ans = 0;
pr[b] = a;
deque <int> v;
while (a != -1) {
v.push_front(a);
a = pr[a];
}
for (int i = v.size() - 1; i >= 0; i --) {
ans += get(c[v[i]] - 1);
upd(c[v[i]]);
}
for (int i = 0; i < v.size(); i ++)
c[v[i]] = c[b];
printf("%lld\n", ans);
memset(t,0,sizeof(t));
}
}
컴파일 시 표준 에러 (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... | ||||
