QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#294056 | #6188. Elliptic Curve Problem | Radewoosh# | AC ✓ | 1437ms | 56836kb | C++23 | 3.6kb | 2023-12-30 03:10:45 | 2023-12-30 03:10:47 |
Judging History
answer
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define shandom_ruffle random_shuffle
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
using mag=__int128;
ll p, gl, gr;
ll d;
ll gloret;
pll operator +(pll a, pll b)
{
return {a.first+b.first, a.second+b.second};
}
pll operator *(pll a, ll b)
{
return {a.first*b, a.second*b};
}
ll f(ll v)
{
return (v*(mag)v+d)/p+1;
}
ll polenad(ll a, ll b, ll g=1)
{
ll fa=f(a);
ll fb=f(b);
ll pole2=(b-a)*(p+1-fa+p+1-fb);
ll bok=b-a+p-fa+p-fb+g;
return pole2+bok+2-2*(p+1-fb);
}
ll cel;
pll stos;
void przesun(pll v, ll g=1)
{
gloret+=polenad(stos.first, v.first, g);
stos=v;
}
mag kwa(ll v)
{
return v*(mag)v;
}
int li1, li2;
int check(pll v)
{
return v.first<=cel && f(v.first)==v.second;
}
void dfs(const pll &lew, const pll &pra)
{
li1++;
if (stos.first+lew.first+pra.first>cel)
return;
if (f(stos.first+pra.first)>stos.second+pra.second)
return;
if (f(stos.first+lew.first)<=stos.second+lew.second)
return;
pll sr=lew+pra;
//~ if (kwa(stos.first+sr.first)+d>=(stos.second+sr.second)*(mag)p && 2*(stos.first+sr.first)*(mag)pra.first>=pra.second*(mag)p)
//~ return;
if (kwa(stos.first+sr.first)+d>=(stos.second+sr.second)*(mag)p && 2*(stos.first+sr.first)*pra.first>=pra.second*p)
return;
dfs(lew, sr);
if (f(stos.first+sr.first)==stos.second+sr.second)
{
ll bsb=2;
while(check(stos+(sr*bsb)))
bsb*=2;
ll bsa=bsb/2;
bsb--;
while(bsa<bsb)
{
ll bss=(bsa+bsb+2)>>1;
if (check(stos+(sr*bss)))
bsa=bss;
else
bsb=bss-1;
}
przesun(stos+(sr*bsa), bsa);
}
dfs(sr, pra);
}
ll solve()
{
gloret=0;
stos={1, f(1)};
cel=p/2;
while(stos.first<cel && f(stos.first+1)==f(1))
{
ll x=stos.first+1;
ll y=f(1);
przesun({x, y});
}
li1=0;
li2=0;
dfs({1, 0}, {0, 1});
debug() << imie(li1);
debug() << imie(li2);
gloret+=2*(p+1-f(cel));
return gloret;
}
int main()
{
scanf("%lld%lld%lld", &p, &gl, &gr);
ll wyn=0;
d=p-gl;
wyn-=solve();
d=p-(gr+1);
wyn+=solve();
wyn/=2;
printf("%lld\n", wyn);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3748kb
input:
11 3 8
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 68ms
memory: 8620kb
input:
998244353 11451400 919810000
output:
454174074
result:
ok 1 number(s): "454174074"
Test #3:
score: 0
Accepted
time: 1403ms
memory: 51036kb
input:
96311898227 25437319919 55129361817
output:
14846091352
result:
ok 1 number(s): "14846091352"
Test #4:
score: 0
Accepted
time: 1386ms
memory: 56192kb
input:
93361455259 23166562299 23393760915
output:
113606479
result:
ok 1 number(s): "113606479"
Test #5:
score: 0
Accepted
time: 1387ms
memory: 39476kb
input:
95670332497 15858139735 18812394512
output:
1477133816
result:
ok 1 number(s): "1477133816"
Test #6:
score: 0
Accepted
time: 1354ms
memory: 43360kb
input:
94221254297 78612110347 90331192055
output:
5859602618
result:
ok 1 number(s): "5859602618"
Test #7:
score: 0
Accepted
time: 1356ms
memory: 54788kb
input:
92756073587 18915851957 32881684894
output:
6982950261
result:
ok 1 number(s): "6982950261"
Test #8:
score: 0
Accepted
time: 1355ms
memory: 47056kb
input:
93651628361 3508055978 32362767220
output:
14427310592
result:
ok 1 number(s): "14427310592"
Test #9:
score: 0
Accepted
time: 1395ms
memory: 53136kb
input:
97506758381 48269906857 58513759044
output:
5121898347
result:
ok 1 number(s): "5121898347"
Test #10:
score: 0
Accepted
time: 1437ms
memory: 56836kb
input:
99954950231 20710324571 44996152988
output:
12142951150
result:
ok 1 number(s): "12142951150"
Test #11:
score: 0
Accepted
time: 1417ms
memory: 45896kb
input:
99367158071 38747300608 85189731653
output:
23221174712
result:
ok 1 number(s): "23221174712"
Test #12:
score: 0
Accepted
time: 1425ms
memory: 52840kb
input:
99936206351 6721710119 93710740278
output:
43494512281
result:
ok 1 number(s): "43494512281"