結果

問題 No.318 学学学学学
ユーザー FF256grhyFF256grhy
提出日時 2015-12-11 12:30:29
言語 C90
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,768 bytes
コンパイル時間 1,285 ms
コンパイル使用メモリ 25,616 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-13 10:53:34
合計ジャッジ時間 5,507 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 43 ms
4,348 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 42 ms
4,352 KB
testcase_17 AC 58 ms
4,348 KB
testcase_18 AC 43 ms
4,352 KB
testcase_19 AC 59 ms
4,352 KB
testcase_20 AC 37 ms
4,356 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,356 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define MAX 100001
#define L 250

int n, a[MAX];
int tree[2][MAX], tree_ptr = 1, val[MAX], first[MAX], last[MAX], leaf_ptr = 1;
int b[400][L], is_all[400], all_val[400];

void add_tree(int v, int p) {
	int i, q = 0;
	for(i = 29; 0 <= i; i--) {
		int *r = &tree[(v / (1 << i)) % 2][q];
		if(*r == 0) {
			if(i != 0) {
				*r = tree_ptr++;
			} else {
				*r = leaf_ptr++;
			}
		}
		q = *r;
	}
	
	if(val[q] == 0) {
		val[q] = v;
		first[q] = p;
	} else {
		last[q] = p;
	}
	
	return;
}

void flip_all(int v, int p) {
	all_val[p] = v;
	is_all[p] = 1;
	
	return;
}

void flip_part(int v, int p, int f, int l) {
	if(f == 0 && l == L - 1) { flip_all(v, p); return; }

	int i;
	if(is_all[p] == 0) {
		for(i = f; i <= l; i++) { b[p][i] = v; }
	} else {
		for(i = 0; i < L; i++) {
			b[p][i] = (f <= i && i <= l ? v : all_val[p]);
		}
	}
	is_all[p] = 0;
	
	return;
}

void flip(int v, int f, int l) {
	int i;
	if(f / L == l / L) {
		flip_part(v, f / L, f % L, l % L);
	} else {
		flip_part(v, f / L, f % L, L - 1);
		for(i = f / L + 1; i < l / L; i++) { flip_all(v, i); }
		flip_part(v, l / L,     0, l % L);
	}
	
	return;
}

void search(int q, int h) {
	if(h != 0 && q == 0) { return; }
	
	if(h < 30) {
		search(tree[0][q], h + 1);
		search(tree[1][q], h + 1);
	} else {
		flip(val[q], first[q], (last[q] == 0 ? first[q] : last[q]));
	}
	
	return;
}

void print() {
	int i, j;
	for(i = 0; i < (n + L - 1) / L; i++) {
	for(j = 0; j < L; j++) {
		if(L * i + j == n) { break; }
		printf("%s%d", (i == 0 && j == 0 ? "" : " "), (is_all[i] ? all_val[i] : b[i][j]) );
	}
	}
	printf("\n");
	
	return;
}

int main(void) {
	scanf("%d", &n);
	int i;
	for(i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		add_tree(a[i], i);
	}
	
	search(0, 0);
	
	print();
	
	return 0;
}
0