結果

問題 No.2220 Range Insert & Point Mex
ユーザー tailstails
提出日時 2023-02-18 13:37:22
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 2,329 bytes
コンパイル時間 1,473 ms
コンパイル使用メモリ 32,336 KB
実行使用メモリ 11,876 KB
最終ジャッジ日時 2023-09-28 18:20:30
合計ジャッジ時間 3,106 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 14 ms
11,772 KB
testcase_14 AC 15 ms
11,760 KB
testcase_15 AC 15 ms
11,824 KB
testcase_16 AC 15 ms
11,836 KB
testcase_17 AC 15 ms
11,868 KB
testcase_18 AC 15 ms
11,760 KB
testcase_19 AC 15 ms
11,876 KB
testcase_20 AC 8 ms
9,416 KB
testcase_21 AC 8 ms
9,552 KB
testcase_22 AC 9 ms
9,524 KB
testcase_23 AC 13 ms
11,872 KB
testcase_24 AC 11 ms
10,896 KB
testcase_25 AC 10 ms
9,612 KB
testcase_26 AC 13 ms
11,420 KB
testcase_27 AC 8 ms
7,812 KB
testcase_28 AC 5 ms
6,188 KB
testcase_29 AC 6 ms
6,532 KB
testcase_30 AC 5 ms
6,568 KB
testcase_31 AC 11 ms
11,052 KB
testcase_32 AC 9 ms
9,204 KB
testcase_33 AC 8 ms
9,168 KB
testcase_34 AC 11 ms
10,272 KB
testcase_35 AC 11 ms
10,096 KB
testcase_36 AC 10 ms
9,868 KB
testcase_37 AC 10 ms
10,008 KB
testcase_38 AC 13 ms
11,180 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘mkwd’:
main.c:68:13: warning: multi-character character constant [-Wmultichar]
  unsigned v='0000';
             ^~~~~~
main.c: In function ‘main’:
main.c:152:3: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
   write(1,wp,wbuf+sizeof wbuf-wp);
   ^~~~~
main.c:154:2: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
  _exit(0);
  ^~~~~
main.c:154:2: warning: incompatible implicit declaration of built-in function ‘_exit’

ソースコード

diff #

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

#define getrp() ({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({long _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) ({ulong _z=v;do*--wp=_z%10+48;while(_z/=10);})
#define rep(v,e) for(long v=0;v<e;++v)
#define rrep(v,e) for(long v=e;v--;)
#define ctz __builtin_ctzl

typedef unsigned long ulong;
char wbuf[1<<25];

void sort_aux(ulong*a,ulong*b,int n,int ph){
	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;
	}
	if(ph==0){
		for(int i=0;i<n;++i){
			b[c[a[i]&255]++]=a[i]>>8|a[i]<<56;
		}
	}else{
		for(int i=0;i<n;++i){
			b[c[a[i]&255]++]=a[i]>>40|a[i]<<24;
		}
	}
}

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

ulong e[300000*2];

ulong b0,b1[1<<6],b2[1<<12];

void initb(){
	b0=~0ul;
	rep(i,1<<6){
		b1[i]=~0ul;
	}
	rep(i,1<<12){
		b2[i]=~0ul;
	}
}

int c[100000];
int r[100000];

unsigned wd[10000];
char wdlz[10000];

void mkwd(){
	unsigned v='0000';
	long i=0;
	rep(a,10){
		rep(b,10){
			rep(c,10){
				rep(d,10){
					wd[i++]=v;
					v+=1<<24;
				}
				v+=(1<<16)-(10<<24);
			}
			v+=(1<<8)-(10<<16);
		}
		v+=(1<<0)-(10<<8);
	}
	rep(j,1000) wdlz[j]=1;
	rep(j,100) wdlz[j]=2;
	rep(j,10) wdlz[j]=3;
}

int main(){
	char*rp=getrp();
	long n=rd();
	long j=0;
	rep(i,n){
		long l=rd();
		long r=rd();
		long a=rd();
		if(a<100000){
			e[j++]=a<<32|l<<2|0;
			e[j++]=a<<32|r<<2|2;
		}
	}
	long q=rd();
	rep(i,q){
		long x=rd();
		e[j++]=i<<32|x<<2|1;
	}
	sort(e,j);

	initb();
	
	rep(i,j){
		long t=e[i]&3;
		long a=e[i]>>32;
		if(t==0){
			if(!c[a]++){
				if(!(b2[a>>6]&=~(1ul<<a))){
					if(!(b1[a>>12]&=~(1ul<<(a>>6)))){
						b0&=~(1ul<<(a>>12));
					}
				}
			}
		}
		if(t==1){
			long d=ctz(b0);
			d=d<<6|ctz(b1[d]);
			d=d<<6|ctz(b2[d]);
			r[a]=d;
		}
		if(t==2){
			if(!--c[a]){
				b2[a>>6]|=1ul<<a;
				b1[a>>12]|=1ul<<(a>>6);
				b0|=1ul<<(a>>12);
			}
		}
	}

	mkwd();
	{
		char*wp=wbuf+sizeof wbuf;
		rrep(i,q){
			*--wp='\n';
			long v=r[i];
			if(v>=10000){
				wp-=4;
				*(unsigned*)wp=wd[v%10000];
				v/=10000;
			}
			wp-=4;
			*(unsigned*)wp=wd[v];
			wp+=wdlz[v];
		}
		write(1,wp,wbuf+sizeof wbuf-wp);
	}
	_exit(0);
}
0