結果

問題 No.2242 Cities and Teleporters
コンテスト
ユーザー 👑 tails
提出日時 2023-03-11 15:52:58
言語 C90(gcc15)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,907 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 176 ms
コンパイル使用メモリ 29,064 KB
最終ジャッジ日時 2026-02-24 01:13:10
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c: In function 'sort_aux':
main.c:20:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   20 |         for(int i=0;i<1024;++i){
      |         ^~~
main.c:20:9: note: use option '-std=c99', '-std=gnu99', '-std=c11' or '-std=gnu11' to compile your code
main.c:23:17: error: redefinition of 'i'
   23 |         for(int i=0;i<n;++i){
      |                 ^
main.c:20:17: note: previous definition of 'i' with type 'int'
   20 |         for(int i=0;i<1024;++i){
      |                 ^
main.c:23:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   23 |         for(int i=0;i<n;++i){
      |         ^~~
main.c:27:17: error: redefinition of 'i'
   27 |         for(int i=0;i<1024;++i){
      |                 ^
main.c:23:17: note: previous definition of 'i' with type 'int'
   23 |         for(int i=0;i<n;++i){
      |                 ^
main.c:27:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   27 |         for(int i=0;i<1024;++i){
      |         ^~~
main.c:33:17: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   33 |                 for(int i=0;i<n;++i){
      |                 ^~~
main.c:37:17: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   37 |                 for(int i=0;i<n;++i){
      |                 ^~~
main.c: In function 'main':
main.c:59:13: error: expected ';' before 'i'
   59 |         rep(i,n*2){
      |             ^
main.c:8:32: note: in definition of macro 'rep'
    8 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                ^
main.c:59:13: error: 'i' undeclared (first use in this function)
   59 |         rep(i,n*2){
      |             ^
main.c:8:36: note: in definition of macro 'rep'
    8 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                    ^
main.c:59:13: note: each undeclared identifier is reported only once for each function it appears in

ソースコード

diff #
raw source code

#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][400000];

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=-1,v=-1;
		rep(i,n*2){
			if(v!=(int)g[i]){
				v=g[i];
				++j;
			}
			int k=g[i]>>32;
			if(k<n){
				h[k]=j;
			}else{
				t[k-n]=j;
			}
		}
	}
	rep(i,200000){
		chmax(e[0][h[i]],t[i]);
	}
	rep3(i,1,400000){
		chmax(e[0][i],e[0][i-1]);
	}
	rep3(k,1,18){
		rep(i,400000){
			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