結果

問題 No.885 アマリクエリ
ユーザー tailstails
提出日時 2021-12-24 17:05:08
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,263 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 32,452 KB
実行使用メモリ 10,308 KB
最終ジャッジ日時 2023-10-19 19:34:39
合計ジャッジ時間 3,256 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
7,480 KB
testcase_01 AC 16 ms
10,284 KB
testcase_02 AC 21 ms
10,308 KB
testcase_03 AC 6 ms
8,356 KB
testcase_04 AC 6 ms
8,456 KB
testcase_05 AC 4 ms
7,576 KB
testcase_06 AC 4 ms
6,696 KB
testcase_07 AC 3 ms
7,284 KB
testcase_08 AC 4 ms
5,432 KB
testcase_09 AC 19 ms
10,284 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'main':
main.c:58:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   58 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:59:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   59 |         _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];

typedef struct{
	ulong m;
	ulong s;
}segt;

#define N (1<<17)
segt segs[N<<1];

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

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