結果
| 問題 |
No.2650 [Cherry 6th Tune *] セイジャク
|
| コンテスト | |
| ユーザー |
chro_96
|
| 提出日時 | 2024-02-23 22:26:52 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 129 ms / 2,500 ms |
| コード長 | 2,225 bytes |
| コンパイル時間 | 984 ms |
| コンパイル使用メモリ | 32,000 KB |
| 実行使用メモリ | 15,780 KB |
| 最終ジャッジ日時 | 2024-09-29 07:20:55 |
| 合計ジャッジ時間 | 6,599 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
ソースコード
#include <stdio.h>
#include <stdlib.h>
typedef struct tree {
int l;
int r;
struct tree *p;
} tree;
int cmp_int (const void *ap, const void *bp) {
int a = *(int *)ap;
int b = *(int *)bp;
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
}
tree *get_root (tree *t) {
if (t == NULL || t->p == NULL) {
return t;
}
t->p = get_root(t->p);
return t->p;
}
int main () {
int n = 0;
int a = 0;
int x[100000] = {};
int t = 0;
int l[100000] = {};
int r[100000] = {};
int res = 0;
int ans[300000] = {};
tree tr[300000] = {};
int sorted[300000][3] = {};
int ucnt = 0;
res = scanf("%d", &n);
res = scanf("%d", &a);
for (int i = 0; i < n; i++) {
res = scanf("%d", x+i);
sorted[i][0] = x[i];
sorted[i][1] = i;
sorted[i][2] = 0;
}
res = scanf("%d", &t);
for (int i = 0; i < t; i++) {
res = scanf("%d", l+i);
res = scanf("%d", r+i);
sorted[n+2*i][0] = l[i];
sorted[n+2*i][1] = i;
sorted[n+2*i][2] = 1;
sorted[n+2*i+1][0] = r[i];
sorted[n+2*i+1][1] = i;
sorted[n+2*i+1][2] = 2;
}
qsort(sorted, n+2*t, sizeof(int)*3, cmp_int);
ucnt = 1;
if (sorted[0][2] == 0) {
x[sorted[0][1]] = 0;
} else if (sorted[0][2] == 1) {
l[sorted[0][1]] = 0;
} else {
r[sorted[0][1]] = 0;
}
for (int i = 1; i < n+2*t; i++) {
if (sorted[i][0] != sorted[i-1][0]) {
sorted[ucnt][0] = sorted[i][0];
ucnt++;
}
if (sorted[i][2] == 0) {
x[sorted[i][1]] = ucnt-1;
} else if (sorted[i][2] == 1) {
l[sorted[i][1]] = ucnt-1;
} else {
r[sorted[i][1]] = ucnt-1;
}
}
for (int i = 0; i < ucnt; i++) {
tr[i].l = i;
tr[i].r = i;
tr[i].p = NULL;
ans[i] = -1;
}
for (int i = t; i > 0; i--) {
int idx = l[i-1];
tree *rt = NULL;
while (idx <= r[i-1]) {
tree *tmp_rt = get_root(tr+idx);
if (ans[idx] < 0) {
ans[idx] = i;
}
if (rt == NULL) {
rt = tmp_rt;
} else if (rt != tmp_rt) {
tmp_rt->p = rt;
rt->r = tmp_rt->r;
}
idx = rt->r+1;
}
}
for (int i = 0; i < n; i++) {
printf("%d\n", ans[x[i]]);
}
return 0;
}
chro_96