結果

問題 No.2002 Range Swap Query
ユーザー 👑 ygussanyygussany
提出日時 2022-06-12 13:20:15
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,031 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 31,924 KB
実行使用メモリ 6,044 KB
最終ジャッジ日時 2023-10-24 07:01:46
合計ジャッジ時間 4,871 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define SIZE 667
#define NUM 300

void swap(int* a, int* b)
{
	if (a == b) return;
	*a ^= *b;
	*b ^= *a;
	*a ^= *b;
}

int main()
{
	int i, N, K, Q, A[200001], B[200001];
	scanf("%d %d %d", &N, &K, &Q);
	for (i = 1; i <= K; i++) scanf("%d %d", &(A[K-i]), &(B[K-i]));
	
	int j, k = K / SIZE;
	static int block[NUM][400001], tmp[400001];
	for (i = 0; i < k; i++) {
		for (j = 1; j <= N; j++) tmp[j] = j;
		for (j = 0; j < SIZE && j + i * SIZE < K; j++) swap(&(tmp[A[j+i*SIZE]]), &(tmp[B[j+i*SIZE]]));
		for (j = 1; j <= N; j++) block[i][tmp[j]] = j;
	}
	
	int q, L, R, X;
	for (q = 1; q <= Q; q++) {
		scanf("%d %d %d", &L, &R, &X);
		L = K - R;
		R = K - L;
		for (j = L; j <= R && j % SIZE != 0; j++) {
			if (X == A[j]) X = B[j];
			else if (X == B[j]) X = A[j];
		}
		if (j <= R) {
			for (i = j / SIZE; (i + 1) * SIZE <= R; i++) X = block[i][X];
			for (j = i * SIZE; j <= R; j++) {
				if (X == A[j]) X = B[j];
				else if (X == B[j]) X = A[j];
			}
		}
		printf("%d\n", X);
	}
	fflush(stdout);
	return 0;
}
0