結果

問題 No.1558 Derby Live
ユーザー tpc011854tpc011854
提出日時 2021-06-26 00:14:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,940 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 34,940 KB
実行使用メモリ 7,000 KB
最終ジャッジ日時 2023-09-07 15:11:19
合計ジャッジ時間 7,496 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>

struct SegT {
	int l,r;
	int d[25];
};
SegT t[200005];
int len = -1;

void build(int p,int l,int r){
	t[p].l = l, t[p].r = r;
	if(l==r){
		return ;
	}
	else{
		int m = (l+r)/2;
		build(2*p, l, m);
		build(2*p+1, m+1, r);
	}
}

SegT merge(const SegT& u, const SegT& v){
	SegT res;
	res.l = u.l, res.r = v.r;
	for(int i = 1; i <= len; i++) res.d[i] = u.d[v.d[i]];
	return res;
}

void change(int p, int x, int d[]){
	if(t[p].l == t[p].r){
		for(int i = 1; i <= len; i++) t[p].d[i] = d[i];
	}
	else{
		int m = (t[p].l+t[p].r)/2;
		if(x<=m) change(2*p, x, d);
		else change(2*p+1,x,d);
		t[p] = merge(t[2*p],t[2*p+1]);
	}
}

SegT ask(int p,int l,int r){
	if(l<=t[p].l && r>=t[p].r) return t[p];
	else{
		int m = (t[p].l+t[p].r)/2;
		if(r<=m) return ask(2*p, l, r);
		else if(l>=m+1) return ask(2*p+1, l, r);
		else return merge(ask(2*p,l,r), ask(2*p+1,l,r));
	}
}

void inv(int d[]){
	int dd[25];
	for(int i = 1; i <= len; i++){
		dd[d[i]] = i;
	} 
	for(int i = 1; i <= len; i++) d[i] = dd[i];
}

int main(){
	int n,m,q;
	scanf("%d%d%d",&n,&m,&q);
	len = n;
	build(1,1,m);
	//printf("done\n");
	for(int rnd = 0; rnd < q; rnd++){
		int order;
		scanf("%d",&order);
		if(order==1){
			int p[25];
			int u;
			scanf("%d",&u);
			for(int i = 1; i <= n; i++) scanf("%d",&p[i]);
			inv(p);
			change(1,u,p);
		}
		else if(order==2){
			int u;
			scanf("%d",&u);
			SegT res = ask(1,1,u);
			for(int i = 1; i <= n; i++) printf("%d ",res.d[i]);
			printf("\n");
		}
		else{
			int u,v;
			scanf("%d%d",&u,&v);
			u--;
			SegT resU;
			if(u!=0) 
				resU = ask(1,1,u);
			else
				for(int i = 1; i <= len; i++) resU.d[i] = i;
			SegT resV = ask(1,1,v);
			int rankU[25], rankV[25];
			for(int i = 1; i <= n; i++) rankU[resU.d[i]] = i, rankV[resV.d[i]] = i;
			int res = 0;
			for(int i = 1; i <= n; i++){
				int add = rankV[resU.d[i]] - i;
				if(add < 0) add *= -1;
				res += add;
			}
			printf("%d\n",res);
		}
	}
	
	return 0;
}
0