結果

問題 No.1746 Sqrt Integer Segments
ユーザー tailstails
提出日時 2023-09-12 10:23:45
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,393 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 30,256 KB
実行使用メモリ 12,904 KB
最終ジャッジ日時 2023-09-12 10:23:49
合計ジャッジ時間 3,150 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,352 KB
testcase_01 AC 7 ms
7,476 KB
testcase_02 AC 29 ms
12,404 KB
testcase_03 AC 22 ms
12,140 KB
testcase_04 AC 24 ms
12,132 KB
testcase_05 AC 36 ms
12,876 KB
testcase_06 AC 20 ms
11,988 KB
testcase_07 AC 15 ms
11,564 KB
testcase_08 AC 30 ms
12,380 KB
testcase_09 AC 38 ms
12,876 KB
testcase_10 AC 20 ms
11,940 KB
testcase_11 AC 35 ms
12,636 KB
testcase_12 AC 38 ms
12,904 KB
testcase_13 AC 39 ms
12,832 KB
testcase_14 AC 38 ms
12,848 KB
testcase_15 AC 37 ms
12,788 KB
testcase_16 AC 38 ms
12,896 KB
testcase_17 AC 27 ms
12,368 KB
testcase_18 AC 7 ms
7,732 KB
testcase_19 AC 7 ms
7,728 KB
testcase_20 AC 8 ms
7,836 KB
testcase_21 AC 11 ms
8,084 KB
testcase_22 AC 11 ms
8,076 KB
testcase_23 AC 8 ms
7,708 KB
testcase_24 AC 14 ms
8,732 KB
testcase_25 AC 15 ms
8,728 KB
testcase_26 AC 15 ms
8,688 KB
testcase_27 AC 14 ms
9,044 KB
testcase_28 AC 15 ms
9,172 KB
testcase_29 AC 15 ms
9,100 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(n);
	long z=0;
	unsigned long h=1;
	{
		unsigned long h2=h&HH_MASK;
		hh[h2]=h;
		z+=c[h2]++;
	}
	while(n--){
		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