結果

問題 No.3134 二分探索木
ユーザー tails
提出日時 2025-05-06 02:04:00
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,388 bytes
コンパイル時間 879 ms
コンパイル使用メモリ 27,648 KB
実行使用メモリ 9,280 KB
最終ジャッジ日時 2025-05-06 02:04:05
合計ジャッジ時間 3,259 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:78:9: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
   78 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:79:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
   79 |         _exit(0);
      |         ^~~~~
main.c:79:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]
main.c:72:15: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   72 |         wp[-1]='\n';
      |         ~~~~~~^~~~~
main.c:11:6: note: at offset -1 into destination object ‘wbuf’ of size 33554432
   11 | char wbuf[1<<25];
      |      ^~~~

ソースコード

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() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) {unsigned _z=v,_n=0;long _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;}
#define rep(v,e) for(typeof(e)v=0;v<e;++v)

typedef unsigned long ulong;

char wbuf[1<<25];
int c[200000];
ulong b2;
ulong b1[(200001>>12)+1];
ulong b0[(200001>>6)+1];
struct{
	int s;
	int d;
} ls[200001];

int main(){
	char*wp=wbuf;
	rd_init();
	int n=rd();
	{
		int a=n+1;
		ls[a].d=-1;
		ls[a].s=0;
		b0[a>>6]|=1ul<<(a);
		b1[a>>12]|=1ul<<(a>>6);
		b2|=1ul<<(a>>12);
	}
	rep(i,n){
		int a=rd();
		int k=a+1;
		int j;
		while(1){
			j=__builtin_ctzl(b2&~0ul<<(k>>12));
			ulong x1=b1[j];
			if(j==k>>12){
				x1&=~0ul<<(k>>6);
				if(!x1){
					k=(k&~0<<12)+(1<<12);
					continue;
				}
			}
			j=j<<6|__builtin_ctzl(x1);
			ulong x0=b0[j];
			if(j==k>>6){
				x0&=~0ul<<(k);
				if(!x0){
					k=(k&~0<<6)+(1<<6);
					continue;
				}
			}
			j=j<<6|__builtin_ctzl(x0);
			break;
		}
		int s=ls[j].s;
		c[i]=j-s-2;
		int d=ls[j].d+1;
		wt(d);
		*wp++=' ';
		ls[a].s=s;
		ls[a].d=d;
		ls[j].s=a;
		ls[j].d=d;
		b0[a>>6]|=1ul<<(a);
		b1[a>>12]|=1ul<<(a>>6);
		b2|=1ul<<(a>>12);
	}
	wp[-1]='\n';
	rep(i,n){
		wt(c[i]);
		*wp++=' ';
	}
	wp[-1]='\n';
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0