結果

問題 No.885 アマリクエリ
ユーザー tailstails
提出日時 2021-12-24 17:19:56
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,208 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 32,796 KB
実行使用メモリ 8,460 KB
最終ジャッジ日時 2023-10-19 19:52:27
合計ジャッジ時間 3,312 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
7,484 KB
testcase_01 AC 12 ms
8,240 KB
testcase_02 AC 18 ms
8,264 KB
testcase_03 AC 6 ms
8,360 KB
testcase_04 AC 6 ms
8,460 KB
testcase_05 AC 4 ms
7,580 KB
testcase_06 AC 4 ms
6,700 KB
testcase_07 AC 4 ms
7,288 KB
testcase_08 AC 4 ms
5,436 KB
testcase_09 AC 15 ms
8,240 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'main':
main.c:54:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   54 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:55:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   55 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

#define rd_skip() while(*rp++>=48)
#define rd(v) long v=0;{long _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define WTHI(v) {ulong _z=v,_n=0,_d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(ulong*)wp=_d;wp+=_n;}
#define WTLO(v) {ulong _z=v,_n=8,_d=0;while(_d=_d<<8|0x30|_z%10,_z/=10,--_n);*(ulong*)wp=_d;wp+=8;}
#define wt(v) if(v>=100000000){WTHI(v/100000000);WTLO(v);}else{WTHI(v);}
#define rep(v,e) for(long v=0;v<e;++v)
#define rrep3(v,s,e) for(long v=e;--v>=s;)
#define max(a,b) (a>=b?a:b)
	
typedef unsigned long ulong;
char*mmap();
char wbuf[1<<25];

#define N (1<<17)
unsigned segm[N<<1];
ulong segs[N<<1];

void f(long i,unsigned x){
	if(segm[i]>=x){
		if(i>=N){
			segs[i]=segm[i]%=x;
		}else{
			f(i*2+0,x);
			f(i*2+1,x);
			segm[i]=max(segm[i*2+0],segm[i*2+1]);
			segs[i]=segs[i*2+0]+segs[i*2+1];
		}
	}
}

int main(){
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd(n);
	rep(i,n){
		rd(a);
		segm[N+i]=segs[N+i]=a;
	}
	rrep3(i,1,N){
		segm[i]=max(segm[i*2+0],segm[i*2+1]);
		segs[i]=segs[i*2+0]+segs[i*2+1];
	}
	char*wp=wbuf;
	rd_skip();
	while(*rp){
		rd(x);
		f(1,x);
		long z=segs[1];
		wt(z);
		*wp++='\n';
	}
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0