結果

問題 No.1746 Sqrt Integer Segments
ユーザー tailstails
提出日時 2021-11-18 01:27:02
言語 C
(gcc 12.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,397 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 30,204 KB
実行使用メモリ 12,860 KB
最終ジャッジ日時 2023-10-11 10:38:26
合計ジャッジ時間 3,862 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,356 KB
testcase_01 AC 7 ms
7,392 KB
testcase_02 AC 30 ms
12,388 KB
testcase_03 AC 22 ms
12,020 KB
testcase_04 AC 25 ms
12,204 KB
testcase_05 AC 38 ms
12,848 KB
testcase_06 AC 19 ms
11,928 KB
testcase_07 AC 14 ms
11,620 KB
testcase_08 AC 30 ms
12,468 KB
testcase_09 AC 38 ms
12,824 KB
testcase_10 AC 19 ms
11,932 KB
testcase_11 AC 37 ms
12,704 KB
testcase_12 AC 38 ms
12,852 KB
testcase_13 AC 38 ms
12,784 KB
testcase_14 AC 39 ms
12,860 KB
testcase_15 AC 39 ms
12,776 KB
testcase_16 AC 39 ms
12,828 KB
testcase_17 RE -
testcase_18 AC 8 ms
7,736 KB
testcase_19 AC 8 ms
7,812 KB
testcase_20 AC 8 ms
7,816 KB
testcase_21 AC 11 ms
8,036 KB
testcase_22 AC 11 ms
8,036 KB
testcase_23 AC 10 ms
7,776 KB
testcase_24 AC 16 ms
8,824 KB
testcase_25 AC 16 ms
8,684 KB
testcase_26 AC 16 ms
8,776 KB
testcase_27 AC 16 ms
9,168 KB
testcase_28 AC 16 ms
9,176 KB
testcase_29 AC 16 ms
9,180 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘f2’ 内:
main.c:75:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   75 |         write(1,wp,wbuf+sizeof wbuf-wp);
      |         ^~~~~
main.c:76:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   76 |         _exit(0);
      |         ^~~~~
      |         _Exit
main.c: トップレベル:
main.c:79:1: 警告: 戻り値の型をデフォルトの ‘int’ にします [-Wimplicit-int]
   79 | main(){
      | ^~~~

ソースコード

diff #

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

char*mmap();

#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 wt(v) {long _z=v;do*--wp=_z%10+48;while(_z/=10);}

#define SIEVE_N 1000000
unsigned sieve[SIEVE_N/2+1][2];
void mksieve(){
	for(long i=3;i*i<SIEVE_N;i+=2){
		if(sieve[i>>1][0]==0){
			long k=i;
			for(long j=i*i>>1;j<SIEVE_N/2;j+=i){
				sieve[j][0]=i;
				sieve[j][1]=k;
				k+=2;
			}
		}
	}
}

static inline
unsigned long splitmix64(unsigned long x) {
	x += 0x9e3779b97f4a7c15;
	x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
	x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
	return x ^ (x >> 31);
}

#define HH_BITS 19
#define HH_LEN (1<<HH_BITS)
#define HH_MASK (HH_LEN-1)
unsigned long hh[HH_LEN];
int c[HH_LEN];

long f1(){
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd_skip();
	long z=0;
	unsigned long h=1;
	{
		unsigned long h2=h&0x3ffff;
		hh[h2]=h;
		z+=c[h2]++;
	}
	while(*rp){
		rd(a);
		while((a&3)==0){
			a>>=2;
		}
		if((a&1)==0){
			h^=splitmix64(2);
			a>>=1;
		}
		while(a>1){
			h^=splitmix64(sieve[a>>1][0]?:a);
			a=sieve[a>>1][1];
		}
		unsigned long h2=h&HH_MASK;
		while(hh[h2]!=0&&hh[h2]!=h){
			h2=h2+1&HH_MASK;
		}
		hh[h2]=h;
		z+=c[h2]++;
	}
	return z;
}

void f2(long z){
	char wbuf[64],*wp=wbuf+sizeof wbuf;
	wt(z);
	write(1,wp,wbuf+sizeof wbuf-wp);
	_exit(0);
}

main(){
	mksieve();
	f2(f1());
}
0