QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#295803 | #6188. Elliptic Curve Problem | ucup-team484# | AC ✓ | 583ms | 9444kb | C++17 | 1.5kb | 2024-01-01 01:21:11 | 2024-01-01 01:21:12 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define st first
#define nd second
using namespace std;
typedef long long ll;
typedef __int128 lll;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
pair<ll, ll> s[N];
pair<ll, ll> operator+(pair<ll, ll> l, pair<ll, ll> r) {
return {l.st + r.st, l.nd + r.nd};
}
lll solve(ll c, ll p) {
auto above = [&](ll x, ll y) {
return x <= (p - 1) / 2 && x * (lll)x + c < p * (lll)y;
};
auto deriv = [&](ll x, pair<ll, ll> r) {
return 2 * x * r.nd >= r.st * p;
};
lll ans = 0;
ll y = (1 + c) / p + 1, x = 1;
pair<ll, ll> l = {1, 0}; // 1/0
pair<ll, ll> r = {0, 1}; // 0/1
int top = 0;
s[0] = l; // 1/0
while (x < (p - 1) / 2) {
while (above(x + r.nd, y + r.st)) { // walk along convex hull
ans += (y + y + r.st - 1) * (r.nd - 1) / 2 + y - 1;
y += r.st;
x += r.nd;
}
while (top >= 0 && !above(x + r.nd, y + r.st)) { // walk up the tree
l = r;
r = s[top--];
}
while (x + l.nd + r.nd <= (p - 1) / 2) { // walk down the tree
auto d = l + r;
// someone below dy/dx?
if (above(x + d.nd, y + d.st)) {
s[++top] = r;
r = d;
} else if (deriv(x + d.nd, r))
break;
else
l = d;
}
}
return ans + y - 1;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
ll p, l, r; cin >> p >> l >> r;
ll ans = solve(p - l, p) - solve(p - r - 1, p);
cout << ans << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
input:
11 3 8
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 28ms
memory: 4132kb
input:
998244353 11451400 919810000
output:
454174074
result:
ok 1 number(s): "454174074"
Test #3:
score: 0
Accepted
time: 567ms
memory: 7764kb
input:
96311898227 25437319919 55129361817
output:
14846091352
result:
ok 1 number(s): "14846091352"
Test #4:
score: 0
Accepted
time: 555ms
memory: 7280kb
input:
93361455259 23166562299 23393760915
output:
113606479
result:
ok 1 number(s): "113606479"
Test #5:
score: 0
Accepted
time: 568ms
memory: 7000kb
input:
95670332497 15858139735 18812394512
output:
1477133816
result:
ok 1 number(s): "1477133816"
Test #6:
score: 0
Accepted
time: 562ms
memory: 6888kb
input:
94221254297 78612110347 90331192055
output:
5859602618
result:
ok 1 number(s): "5859602618"
Test #7:
score: 0
Accepted
time: 557ms
memory: 7532kb
input:
92756073587 18915851957 32881684894
output:
6982950261
result:
ok 1 number(s): "6982950261"
Test #8:
score: 0
Accepted
time: 561ms
memory: 9444kb
input:
93651628361 3508055978 32362767220
output:
14427310592
result:
ok 1 number(s): "14427310592"
Test #9:
score: 0
Accepted
time: 580ms
memory: 6364kb
input:
97506758381 48269906857 58513759044
output:
5121898347
result:
ok 1 number(s): "5121898347"
Test #10:
score: 0
Accepted
time: 583ms
memory: 8396kb
input:
99954950231 20710324571 44996152988
output:
12142951150
result:
ok 1 number(s): "12142951150"
Test #11:
score: 0
Accepted
time: 583ms
memory: 8384kb
input:
99367158071 38747300608 85189731653
output:
23221174712
result:
ok 1 number(s): "23221174712"
Test #12:
score: 0
Accepted
time: 582ms
memory: 7648kb
input:
99936206351 6721710119 93710740278
output:
43494512281
result:
ok 1 number(s): "43494512281"