結果

問題 No.2242 Cities and Teleporters
ユーザー tailstails
提出日時 2023-03-11 16:05:53
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 201 ms / 3,000 ms
コード長 1,910 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 28,116 KB
実行使用メモリ 30,952 KB
最終ジャッジ日時 2023-10-18 10:00:23
合計ジャッジ時間 5,605 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
18,212 KB
testcase_01 AC 10 ms
18,212 KB
testcase_02 AC 10 ms
18,212 KB
testcase_03 AC 10 ms
18,212 KB
testcase_04 AC 10 ms
18,212 KB
testcase_05 AC 126 ms
30,216 KB
testcase_06 AC 135 ms
30,732 KB
testcase_07 AC 127 ms
30,736 KB
testcase_08 AC 201 ms
30,736 KB
testcase_09 AC 104 ms
30,732 KB
testcase_10 AC 31 ms
30,952 KB
testcase_11 AC 46 ms
30,732 KB
testcase_12 AC 47 ms
30,736 KB
testcase_13 AC 63 ms
30,736 KB
testcase_14 AC 105 ms
30,732 KB
testcase_15 AC 66 ms
30,736 KB
testcase_16 AC 92 ms
30,736 KB
testcase_17 AC 135 ms
30,736 KB
testcase_18 AC 61 ms
30,632 KB
testcase_19 AC 122 ms
30,588 KB
testcase_20 AC 68 ms
30,496 KB
testcase_21 AC 58 ms
30,560 KB
testcase_22 AC 131 ms
30,476 KB
testcase_23 AC 108 ms
30,736 KB
testcase_24 AC 65 ms
30,732 KB
testcase_25 AC 38 ms
30,732 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:115:9: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
  115 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:116:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
  116 |         _exit(0);
      |         ^~~~~
main.c:116:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd_skip() while(*rp++>=48)
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) ({unsigned _z=v;int _n=0;ulong _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(ulong*)wp=_d;wp+=_n;})
#define rep(v,e) for(typeof(e) v=0;v<e;++v)
#define rep3(v,s,e) for(typeof(e) v=s;v<e;++v)
#define rrep(v,e) for(typeof(e) v=e;v--;)
#define chmax(v,a) (v=v>=a?v:a)

typedef unsigned long ulong;

ulong ulbuf[1<<22];
#define wbuf ((char*)ulbuf)

void sort_aux(ulong*a,ulong*b,int n,int ph){
	int c[1024];
	for(int i=0;i<1024;++i){
		c[i]=0;
	}
	for(int i=0;i<n;++i){
		++c[a[i]&1023];
	}
	int t=0;
	for(int i=0;i<1024;++i){
		int u=c[i];
		c[i]=t;
		t+=u;
	}
	if(ph==0){
		for(int i=0;i<n;++i){
			b[c[a[i]&1023]++]=a[i]>>10|a[i]<<54;
		}
	}else{
		for(int i=0;i<n;++i){
			b[c[a[i]&1023]++]=a[i]>>44|a[i]<<20;
		}
	}
}

void sort(ulong*a,int n){
	ulong*b=a+n;
	sort_aux(b,a,n,0);
	sort_aux(a,b,n,0);
	sort_aux(b,a,n,1);
}

#define g ulbuf

int h[200000];
int t[200000];
int e[18][200004];

int main(){
	rd_init();
	int n=rd();
	rep(i,n*2){
		g[i+n*2]=rd()|(ulong)i<<32;
	}
	sort(g,n*2);
	{
		int j=0,v=-1;
		rep(i,n*2){
			int k=g[i]>>32;
			if(k<n){
				if(v!=(int)g[i]){
					v=g[i];
					++j;
				}
				h[k]=j;
			}else{
				t[k-n]=j;
			}
		}
	}
	rep(i,200000){
		chmax(e[0][h[i]],t[i]);
	}
	rep3(i,1,200004){
		chmax(e[0][i],e[0][i-1]);
	}
	rep3(k,1,18){
		rep(i,200004){
			e[k][i]=e[k-1][e[k-1][i]];
		}
	}

	char*wp=wbuf;
	rd_skip();
	while(*rp){
		int a=rd()-1;
		int b=rd()-1;
		if(t[a]>=h[b]){
			*wp++='1';
		}else{
			int c=t[a];
			int z=1;
			rrep(k,18){
				if(e[k][c]<h[b]){
					z+=1<<k;
					c=e[k][c];
				}
			}
			if(z<1<<18){
				wt(z+1);
			}else{
				*wp++='-';
				*wp++='1';
			}
		}
		*wp++='\n';
	}
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0