結果

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

コンパイルメッセージ
main.c: In function 'sort_aux':
main.c:19:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   19 |         for(int i=0;i<256;++i){
      |         ^~~
main.c:19:9: note: use option '-std=c99', '-std=gnu99', '-std=c11' or '-std=gnu11' to compile your code
main.c:22:17: error: redefinition of 'i'
   22 |         for(int i=0;i<n;++i){
      |                 ^
main.c:19:17: note: previous definition of 'i' with type 'int'
   19 |         for(int i=0;i<256;++i){
      |                 ^
main.c:22:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   22 |         for(int i=0;i<n;++i){
      |         ^~~
main.c:26:17: error: redefinition of 'i'
   26 |         for(int i=0;i<256;++i){
      |                 ^
main.c:22:17: note: previous definition of 'i' with type 'int'
   22 |         for(int i=0;i<n;++i){
      |                 ^
main.c:26:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   26 |         for(int i=0;i<256;++i){
      |         ^~~
main.c:31:17: error: redefinition of 'i'
   31 |         for(int i=0;i<n;++i){
      |                 ^
main.c:26:17: note: previous definition of 'i' with type 'int'
   26 |         for(int i=0;i<256;++i){
      |                 ^
main.c:31:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   31 |         for(int i=0;i<n;++i){
      |         ^~~
main.c: In function 'main':
main.c:52:13: error: expected ';' before 'i'
   52 |         rep(i,n){
      |             ^
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:52:13: error: 'i' undeclared (first use in this function)
   52 |         rep(i,n){
      |             ^
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:52:13: note: each undeclared identifier is repo

ソースコード

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;

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