QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#121640#6188. Elliptic Curve ProblemCrysflyTL 1ms3420kbC++171.9kb2023-07-08 16:17:272023-07-08 16:17:28

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:17:28]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3420kb
  • [2023-07-08 16:17:27]
  • 提交

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;
}

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;
	if(!in(x-e,y-f)){
		pii K=slope(x-e);
		pii N=mkp(f,e);
	//	cout<<"N,K "<<(ll)N.x<<" "<<(ll)N.y<<" "<<(ll)K.x<<" "<<(ll)K.y<<"\n";
		if(comp(K,N))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);
	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: 3420kb

input:

11 3 8

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Time Limit Exceeded

input:

998244353 11451400 919810000

output:


result: