QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#47254#1175. Bags of CandiesGemini7XAC ✓614ms13536kbC++142.9kb2022-09-06 17:31:092022-09-06 17:31:09

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-06 17:31:09]
  • 评测
  • 测评结果:AC
  • 用时:614ms
  • 内存:13536kb
  • [2022-09-06 17:31:09]
  • 提交

answer

/*
author : Gemini
date : September 6th, 2022
url : https://vjudge.net/contest/512482#problem/I
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=316305;
template<typename T>
void read(T &x){
	T sgn=1;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar())if(ch=='-')sgn=-1;
	for(x=0;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	x*=sgn;
}
ll g[maxn<<1],a[maxn<<1];
int sq,tot,cnt;
int main(){
	int T;
	read(T);
	while(T--){
		ll n;
		read(n);
		if(n==1){
			puts("1");
		}else if(n==2){
			puts("2");
		}else{
			cnt=tot=0;
			sq=sqrt(n);
			for(ll i=1;i<=n;i=a[tot]+1){
				a[++tot]=n/(n/i);
				g[tot]=a[tot]-1;
			}
			auto id=[n](ll x){
				return x<=sq?x:tot-n/x+1; 
			};
			for(int i=2;i<=sq;i++){
				if(g[i]!=g[i-1]){
					cnt++;
					ll lim=1ll*i*i;
					double inv=1.0/i;
					for(int j=tot;a[j]>=lim;j--){
						g[j]-=g[id(a[j]*inv+1e-9)]-cnt+1;
					}
				}
			}
			ll num=g[tot]-g[id(n/2)]+1;
			printf("%lld\n",(n-num+1)/2+num);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3592kb

input:

2
4
9

output:

3
6

result:

ok 2 number(s): "3 6"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3672kb

input:

5
2
3
4
5
6

output:

2
3
3
4
4

result:

ok 5 number(s): "2 3 3 4 4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

5
1111
2018
3333
4006
5555

output:

599
1078
1772
2128
2942

result:

ok 5 number(s): "599 1078 1772 2128 2942"

Test #4:

score: 0
Accepted
time: 2ms
memory: 3716kb

input:

5
26666666
10000000
23456789
27777777
24444442

output:

13730373
5158034
12080298
14301448
12588059

result:

ok 5 number(s): "13730373 5158034 12080298 14301448 12588059"

Test #5:

score: 0
Accepted
time: 614ms
memory: 13536kb

input:

5
47890123456
12345678901
96666666669
85555555558
100000000000

output:

24438086351
6307451722
49300536501
43638011231
50999200118

result:

ok 5 number(s): "24438086351 6307451722 49300536501 43638011231 50999200118"