結果

問題 No.2809 Sort Query
ユーザー tailstails
提出日時 2024-07-19 16:40:21
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1,257 ms / 2,000 ms
コード長 1,853 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 29,340 KB
実行使用メモリ 316,288 KB
最終ジャッジ日時 2024-07-19 16:41:19
合計ジャッジ時間 55,894 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 854 ms
216,064 KB
testcase_02 AC 683 ms
216,320 KB
testcase_03 AC 689 ms
216,448 KB
testcase_04 AC 714 ms
216,448 KB
testcase_05 AC 711 ms
216,192 KB
testcase_06 AC 313 ms
64,128 KB
testcase_07 AC 265 ms
64,000 KB
testcase_08 AC 285 ms
63,872 KB
testcase_09 AC 277 ms
63,872 KB
testcase_10 AC 270 ms
64,000 KB
testcase_11 AC 252 ms
22,912 KB
testcase_12 AC 285 ms
21,760 KB
testcase_13 AC 257 ms
22,912 KB
testcase_14 AC 281 ms
22,912 KB
testcase_15 AC 263 ms
22,912 KB
testcase_16 AC 253 ms
23,040 KB
testcase_17 AC 258 ms
22,912 KB
testcase_18 AC 260 ms
22,912 KB
testcase_19 AC 275 ms
22,912 KB
testcase_20 AC 280 ms
22,400 KB
testcase_21 AC 1,257 ms
316,160 KB
testcase_22 AC 1,250 ms
316,288 KB
testcase_23 AC 1,194 ms
316,160 KB
testcase_24 AC 1,137 ms
316,160 KB
testcase_25 AC 1,255 ms
316,288 KB
testcase_26 AC 898 ms
242,432 KB
testcase_27 AC 915 ms
242,688 KB
testcase_28 AC 897 ms
242,688 KB
testcase_29 AC 955 ms
242,816 KB
testcase_30 AC 852 ms
242,688 KB
testcase_31 AC 248 ms
21,248 KB
testcase_32 AC 206 ms
21,120 KB
testcase_33 AC 209 ms
21,248 KB
testcase_34 AC 205 ms
21,120 KB
testcase_35 AC 202 ms
21,120 KB
testcase_36 AC 252 ms
23,424 KB
testcase_37 AC 248 ms
23,424 KB
testcase_38 AC 254 ms
23,424 KB
testcase_39 AC 243 ms
23,552 KB
testcase_40 AC 244 ms
23,424 KB
testcase_41 AC 818 ms
169,472 KB
testcase_42 AC 759 ms
169,472 KB
testcase_43 AC 787 ms
169,472 KB
testcase_44 AC 734 ms
169,472 KB
testcase_45 AC 866 ms
169,472 KB
testcase_46 AC 711 ms
169,472 KB
testcase_47 AC 748 ms
169,472 KB
testcase_48 AC 743 ms
169,472 KB
testcase_49 AC 766 ms
169,472 KB
testcase_50 AC 724 ms
169,472 KB
testcase_51 AC 166 ms
19,456 KB
testcase_52 AC 104 ms
19,456 KB
testcase_53 AC 122 ms
19,328 KB
testcase_54 AC 100 ms
19,328 KB
testcase_55 AC 98 ms
19,328 KB
testcase_56 AC 633 ms
142,336 KB
testcase_57 AC 480 ms
114,176 KB
testcase_58 AC 403 ms
115,712 KB
testcase_59 AC 451 ms
109,440 KB
testcase_60 AC 469 ms
157,568 KB
testcase_61 AC 638 ms
191,488 KB
testcase_62 AC 454 ms
115,072 KB
testcase_63 AC 548 ms
150,144 KB
testcase_64 AC 728 ms
202,752 KB
testcase_65 AC 403 ms
131,968 KB
testcase_66 AC 2 ms
5,376 KB
testcase_67 AC 2 ms
5,376 KB
testcase_68 AC 1 ms
5,376 KB
testcase_69 AC 2 ms
5,376 KB
testcase_70 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:101:9: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
  101 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:102:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
  102 |         _exit(0);
      |         ^~~~~
main.c:102: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() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define rd_long() ({long _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define WTHI(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 WTLO(v) {unsigned _z=v,_n=8;long _d=0;while(_d=_d<<8|0x30|_z%10,_z/=10,--_n);*(long*)wp=_d;wp+=8;}
#define wt(v) if(v>=100000000){if(v>=10000000000000000l){WTHI(v/10000000000000000l);WTLO(v/100000000%100000000);}else WTHI(v/100000000);WTLO(v%100000000);}else{WTHI(v);}
#define rep(v,e) for(typeof(e)v=0;v<e;++v)
#define times(e) for(typeof(e)_=e;_--;)

typedef unsigned long ulong;

char wbuf[1<<25];
long av[300000];
int at[300000];
int l2;
long aa[900000];
int an;

struct{
	int n,c[2];
}ns[600000*64];
int nn;

long kth(int k){
	long x=0;
	if(at[k]<=l2){
		int j=0;
		times(64){
			x<<=1;
			int c0=ns[j].c[0];
			int c1=ns[j].c[1];
			if(c0&&k<ns[c0].n){
				j=c0;
			}else{
				if(c0)k-=ns[c0].n;
				j=c1;
				x|=1;
			}
		}
	}else{
		x=av[k];
	}
	return x;
}

int main(){
	char*wp=wbuf;
	rd_init();
	int n=rd();
	int q=rd();
	rep(k,n){
		long x=rd_long();
		aa[an++]=x;
		av[k]=x;
	}
	l2=-1;
	nn=1;
	rep(qi,q){
		int t=*rp;
		rp+=2;
		if(t=='1'){
			int k=rd()-1;
			long x=rd_long();
			aa[an++]=-kth(k);
			aa[an++]=x;
			av[k]=x;
			at[k]=qi;
		}
		if(t=='2'){
			rep(i,an){
				long x=aa[i];
				int d=1;
				if(x<0){
					x=-x;
					d=-1;
				}
				int j=0;
				times(64){
					int ci=x<0;
					if(ns[j].c[ci]==0){
						ns[j].c[ci]=nn++;
					}
					j=ns[j].c[ci];
					ns[j].n+=d;
					x<<=1;
				}
			}
			an=0;
			l2=qi;
		}
		if(t=='3'){
			int k=rd()-1;
			long x=kth(k);
			wt((ulong)x);
			*wp++='\n';
		}
	}
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0