QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#121657#6188. Elliptic Curve ProblemCrysflyAC ✓1058ms63976kbC++172.0kb2023-07-08 16:37:012023-07-08 16:37:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-08 16:37:04]
  • 评测
  • 测评结果:AC
  • 用时:1058ms
  • 内存:63976kb
  • [2023-07-08 16:37:01]
  • 提交

answer

// what is matter? never mind. 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
#define int __int128
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

#define x first
#define y second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 200005
#define inf 0x3f3f3f3f

int n;
int p,A,x,y,res;
bool in(int x,int y){
	return p*y>x*x+A;
}
pii slope(int x){
	return mkp(2*x,p);
}
bool comp(pii a,pii b){
	// a.x/a.y >= b.x/b.y
	return a.x*b.y>=a.y*b.x;
}

int step(int a,int b){ 
	int l=1,r=2;
	auto chk=[&](int t){
		return in(x-t*a,y-t*b);
	};
	assert(chk(1));
	while(chk(r))r<<=1,l<<=1;
	while(l+1<r){
		int mid=l+r>>1;
		if(chk(mid))l=mid;
		else r=mid;
	}
	return l;
}

int tim;
void dfs(int a,int b,int c,int d){
	int e=a+c,f=b+d;
	if(x-e<=0||y-f<=0)return;
	++tim;
	if(!in(x-e,y-f)){
		pii K=slope(x-e);
		pii N=mkp(d,c);
	//	cout<<"N,K "<<(ll)N.x<<" "<<(ll)N.y<<" "<<(ll)K.x<<" "<<(ll)K.y<<"\n";
		if(comp(N,K))return;
	}
	if(in(x-e,y-f)) dfs(a,b,e,f);
	if(in(x-e,y-f)) {
		int k=step(e,f);
	//	cout<<"step "<<(ll)e<<" "<<(ll)f<<" "<<(ll)k<<endl;
		int xx=x-k*e;
		int yy=y-k*f;
		res+=((x-xx+1)*(y+yy+1)-(k+1))/2-(x-xx+1)-(yy-1);
		x=xx,y=yy;
	}
	if(in(x-c,y-d)) dfs(e,f,c,d);
}

int work(){
	res=0;
	x=(p-1)/2;
	y=(x*x+A)/p+1;
	dfs(0,1,1,0);
//	cout<<"res "<<(ll)res<<"\n";
	res+=x*(y-1);
	cerr<<"tim "<<(ll)tim<<"\n";
	return res; 
}

signed main()
{
	p=read();
	int l=read(),r=read();
	A=p-l;
	int res=work();
	A=p-r-1;
	res-=work();
	cout<<(ll)res;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3424kb

input:

11 3 8

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 47ms
memory: 7756kb

input:

998244353 11451400 919810000

output:

454174074

result:

ok 1 number(s): "454174074"

Test #3:

score: 0
Accepted
time: 1042ms
memory: 59408kb

input:

96311898227 25437319919 55129361817

output:

14846091352

result:

ok 1 number(s): "14846091352"

Test #4:

score: 0
Accepted
time: 1014ms
memory: 63976kb

input:

93361455259 23166562299 23393760915

output:

113606479

result:

ok 1 number(s): "113606479"

Test #5:

score: 0
Accepted
time: 1050ms
memory: 37660kb

input:

95670332497 15858139735 18812394512

output:

1477133816

result:

ok 1 number(s): "1477133816"

Test #6:

score: 0
Accepted
time: 1018ms
memory: 50200kb

input:

94221254297 78612110347 90331192055

output:

5859602618

result:

ok 1 number(s): "5859602618"

Test #7:

score: 0
Accepted
time: 1014ms
memory: 48376kb

input:

92756073587 18915851957 32881684894

output:

6982950261

result:

ok 1 number(s): "6982950261"

Test #8:

score: 0
Accepted
time: 1012ms
memory: 40576kb

input:

93651628361 3508055978 32362767220

output:

14427310592

result:

ok 1 number(s): "14427310592"

Test #9:

score: 0
Accepted
time: 1024ms
memory: 32416kb

input:

97506758381 48269906857 58513759044

output:

5121898347

result:

ok 1 number(s): "5121898347"

Test #10:

score: 0
Accepted
time: 1058ms
memory: 45036kb

input:

99954950231 20710324571 44996152988

output:

12142951150

result:

ok 1 number(s): "12142951150"

Test #11:

score: 0
Accepted
time: 1050ms
memory: 47792kb

input:

99367158071 38747300608 85189731653

output:

23221174712

result:

ok 1 number(s): "23221174712"

Test #12:

score: 0
Accepted
time: 1055ms
memory: 33608kb

input:

99936206351 6721710119 93710740278

output:

43494512281

result:

ok 1 number(s): "43494512281"