結果

問題 No.2242 Cities and Teleporters
ユーザー tailstails
提出日時 2023-03-11 15:16:23
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 295 ms / 3,000 ms
コード長 1,889 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 27,784 KB
実行使用メモリ 26,864 KB
最終ジャッジ日時 2023-10-18 09:56:29
合計ジャッジ時間 7,288 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
18,220 KB
testcase_01 AC 11 ms
18,220 KB
testcase_02 AC 10 ms
18,220 KB
testcase_03 AC 11 ms
18,220 KB
testcase_04 AC 10 ms
18,220 KB
testcase_05 AC 194 ms
26,128 KB
testcase_06 AC 159 ms
26,644 KB
testcase_07 AC 191 ms
26,648 KB
testcase_08 AC 295 ms
26,648 KB
testcase_09 AC 167 ms
26,644 KB
testcase_10 AC 82 ms
26,864 KB
testcase_11 AC 99 ms
26,644 KB
testcase_12 AC 99 ms
26,648 KB
testcase_13 AC 116 ms
26,648 KB
testcase_14 AC 154 ms
26,644 KB
testcase_15 AC 114 ms
26,648 KB
testcase_16 AC 144 ms
26,648 KB
testcase_17 AC 198 ms
26,648 KB
testcase_18 AC 110 ms
26,544 KB
testcase_19 AC 209 ms
26,500 KB
testcase_20 AC 112 ms
26,408 KB
testcase_21 AC 102 ms
26,472 KB
testcase_22 AC 191 ms
26,388 KB
testcase_23 AC 166 ms
26,648 KB
testcase_24 AC 112 ms
26,644 KB
testcase_25 AC 87 ms
26,644 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:117:9: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
  117 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:118:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
  118 |         _exit(0);
      |         ^~~~~
main.c:118: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;

char wbuf[1<<25];

void sort_aux(unsigned*a,unsigned*b,int n){
	int c[256];
	for(int i=0;i<256;++i){
		c[i]=0;
	}
	for(int i=0;i<n;++i){
		++c[a[i]&255];
	}
	int t=0;
	for(int i=0;i<256;++i){
		int u=c[i];
		c[i]=t;
		t+=u;
	}
	for(int i=0;i<n;++i){
		b[c[a[i]&255]++]=a[i]>>8|a[i]<<24;
	}
}

void sort(unsigned*a,int n){
	unsigned*b=(unsigned*)wbuf;
	sort_aux(a,b,n);
	sort_aux(b,a,n);
	sort_aux(a,b,n);
	sort_aux(b,a,n);
}

unsigned g[200000];
int h[200000];
int t[200000];
int e[18][200000];

int main(){
	rd_init();
	int n=rd();
	rep(i,n){
		h[i]=g[i]=rd();
	}
	sort(g,n);
	rep(i,n){
		int x=h[i];
		int a=0,b=n;
		while(a+1<b){
			int c=a+b>>1;
			if(g[c]<=x){
				a=c;
			}else{
				b=c;
			}
		}
		h[i]=a;
	}
	rep(i,n){
		int x=rd();
		int a=0,b=n;
		while(a+1<b){
			int c=a+b>>1;
			if(g[c]<=x){
				a=c;
			}else{
				b=c;
			}
		}
		t[i]=a;
		chmax(e[0][h[i]],a);
	}
	rep3(i,1,200000){
		chmax(e[0][i],e[0][i-1]);
	}
	rep3(k,1,18){
		rep(i,200000){
			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