QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#54618 | #975. Game | YaoBIG# | AC ✓ | 133ms | 23308kb | C++ | 4.3kb | 2022-10-09 21:00:15 | 2022-10-09 21:00:17 |
Judging History
answer
#include "bits/stdc++.h"
#define rep(i, a, n) for (auto i = a; i <= (n); ++i)
#define revrep(i, a, n) for (auto i = n; i >= (a); --i)
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a).size()
template<class T> bool chmin(T &a, T b) { if (b < a) { a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, T b) { if (b > a) { a = b; return 1; } else return 0; }
using namespace std;
template<class A> string to_string(const A &v) {
bool first = 1;
string res = "{";
for (const auto &x: v) {
if (!first) res += ", ";
first = 0;
res += to_string(x);
}
res += ")";
return res;
}
void debug_out() { cerr << endl; }
template<class H, class... T> void debug_out(const H&h, const T&... t) {
cerr << " " << to_string(h);
debug_out(t...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<int>;
template<class T> struct Point {
using P = Point;
using type = T;
static constexpr T eps = 1e-9;
static constexpr bool isInt = is_integral_v<T>;
static int sgn(T x) { return (x > eps) - (x < -eps); }
static int cmp(T x, T y) { return sgn(x - y); }
T x, y;
P operator +(P a) const { return P{x + a.x, y + a.y}; }
P operator -(P a) const { return P{x - a.x, y - a.y}; }
P operator *(T a) const { return P{x * a, y * a}; }
P operator /(T a) const { return P{x / a, y / a}; }
bool operator ==(P a) { return cmp(x, a.x) == 0 && cmp(y, a.y) == 0; }
T len2() const { return x * x + y * y; }
T len() const { return sqrt(x * x + y * y); }
P unit() const {
if (isInt) return *this;
else return len() <= eps ? P{} : *this / len();
}
T dot(P b) const { return x * b.x + y * b.y; }
T cross(P b) const { return x * b.y - y * b.x; }
P rotate(T theta) const {
P a{cos(theta), sin(theta)};
return P{x * a.x - y * a.y, x * a.y + y * a.x};
}
T project_len(P a, P b) const {
if (isInt) return (*this - a).dot(b - a);
else if (a == b) return 0;
else return (*this - a).dot(b - a) / (b - a).len();
}
T dis_to_line(P a, P b) const {
if (isInt) return (*this - a).cross(b - a);
else if (a == b) return 0;
else return (*this - a).cross(b - a) / (b - a).len();
}
T dis_to_seg(P a, P b) const {
if (project_len(a, b) <= eps) return (*this - a).len();
if (project_len(b, a) <= eps) return (*this - b).len();
return fabs(dis_to_line(a, b));
}
friend string to_string(P p) { return "(" + to_string(p.x) + ", " + to_string(p.y) + ")"; }
};
template<const int &mod> struct Z {
int x;
Z(ll a = 0): x (a % mod) { if (x < 0) x += mod; }
explicit operator int() const { return x; }
Z& operator +=(Z b) { x += b.x; if (x >= mod) x -= mod; return *this; }
Z& operator -=(Z b) { x -= b.x; if (x < 0) x += mod; return *this; }
Z& operator *=(Z b) { x = 1ll * x * b.x % mod; return *this; }
friend Z operator +(Z a, Z b) { return a += b; }
friend Z operator -(Z a, Z b) { return a -= b; }
friend Z operator *(Z a, Z b) { return a *= b; }
Z pow(ll k) const {
Z res = 1, a = *this;
for (; k; k >>= 1, a = a * a) if (k & 1) res = res * a;
return res;
}
Z& operator /=(Z b) {
assert(b.x != 0);
*this = *this * b.pow(mod - 2);
return *this;
}
friend Z operator /(Z a, Z b) { return a /= b; }
friend string to_string(Z a) { return to_string(a.x); }
};
const int mod = 998244353;
using Mint = Z<mod>;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
using T = ll;
using P = Point<T>;
int n; cin >> n;
vector<ll> as(n);
for (auto &x: as) cin >> x;
vector<P> ps(n);
rep(i, 0, n - 1) ps[i] = {i, as[i]};
vector<P> hull;
rep(i, 0, n - 1) {
P a = ps[i];
while (sz(hull) >= 2 && (a - hull.end()[-1]).cross(hull.end()[-1] - hull.end()[-2]) <= 0) {
hull.pop_back();
}
hull.push_back(a);
}
vi nums;
for (auto &p: hull) nums.push_back(p.x);
Mint ans = 0;
rep(i, 0, n - 1) {
int pos = lower_bound(all(nums), i) - nums.begin();
int r = nums[pos];
if (r == i) {
ans += Mint{as[i]};
} else {
int l = nums[pos - 1];
Mint val = Mint{as[l]} * (r - i) + Mint{as[r]} * (i - l);
val /= Mint{r - l};
ans += val;
}
}
ans /= n;
printf("%d\n", (int) ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3744kb
input:
3 3 1 2
output:
499122179
result:
ok "499122179"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3780kb
input:
6 6 1 2 5 3 4
output:
582309211
result:
ok "582309211"
Test #3:
score: 0
Accepted
time: 129ms
memory: 15024kb
input:
500000 131592496991 614154464278 882215024371 954828734583 997777248498 677111110098 927405745589 218490006270 743425189504 391435077446 972647376673 630405853326 714899101544 90679613430 530369364312 763893201576 838136940841 261795310871 187042095193 941416320169 688136558810 554872601435 54089147...
output:
131032905
result:
ok "131032905"
Test #4:
score: 0
Accepted
time: 133ms
memory: 15024kb
input:
500000 421220858944 713224031063 336994376776 404652618849 994886478979 829414359743 316305757515 853349571538 209760384582 147707414760 185696717554 799127062493 617492545107 53250360125 328023561767 733955134735 597561653732 916598190157 579663876723 955327502435 743204270667 366987453720 11387374...
output:
348480416
result:
ok "348480416"
Test #5:
score: 0
Accepted
time: 123ms
memory: 20900kb
input:
500000 771963972281 951878663502 161804581898 999999999990 999999999996 999999999989 999999999979 999999999965 999999999943 641359945099 612980551716 999999999876 999999999841 999999999795 999999999735 999999999668 925643315831 999999999534 999999999449 323521484303 343970139588 999999999191 4816618...
output:
555358133
result:
ok "555358133"
Test #6:
score: 0
Accepted
time: 101ms
memory: 23308kb
input:
500000 731038336473 702417643458 99746958924 750705686043 757261469217 756274960637 253908059872 776928818738 296137376885 108525188952 796596168245 803151951402 809707734549 816263517688 822819300826 829375083951 458946003379 713702318217 849042433322 855598216431 862153999525 868709782603 87526556...
output:
375919639
result:
ok "375919639"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
5000 347931136892 248405930290 545145973932 959711822405 663469739788 271778456420 606252233695 118860304765 575983148404 978665447746 407137591528 87773793124 418700437665 712485983701 221166405070 310847318179 426658720698 812176551095 975518517744 815933288917 682784954397 554770160022 6457887899...
output:
761790956
result:
ok "761790956"
Test #8:
score: 0
Accepted
time: 3ms
memory: 3876kb
input:
5000 548236179275 100704704660 999546081878 999999959902 999999972450 999999914844 999999762365 999999536382 999999228545 999998838310 500922364815 999997959059 999997469194 999996909593 999996348133 999995748919 999995120089 999994485016 359478933956 745710318835 999992536867 999991799874 999991025...
output:
933989751
result:
ok "933989751"
Test #9:
score: 0
Accepted
time: 1ms
memory: 4044kb
input:
5000 423792415313 584164203827 744535958314 904907634367 999999935403 999999901586 999999808334 614614432429 999999600031 999999419574 999999189705 999998934894 999998669832 999998317316 999997938174 999997558147 999997109631 676337496849 999996138497 999995596881 999994995701 999994328103 999993595...
output:
463005503
result:
ok "463005503"
Test #10:
score: 0
Accepted
time: 3ms
memory: 4012kb
input:
5000 194846717164 283755585977 372664371248 461573056586 550481685947 639390308241 728298878142 817207379441 906115813385 995024187855 999999978507 999999969455 999999929108 999999863839 999999761219 999999558974 999999321236 999999044519 999998761833 999998401451 952979572445 999997676207 999997290...
output:
279043762
result:
ok "279043762"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3940kb
input:
5000 91073571943 29005326232 302727879690 408554936320 514381922178 620208815826 726035664215 756479610641 937689356888 999999929358 999999922046 999999912402 999999867083 999999754083 598925718703 637973050717 999999403911 999999270686 999999065292 999998802703 999998471786 999998139358 99999777247...
output:
408133290
result:
ok "408133290"
Test #12:
score: 0
Accepted
time: 0ms
memory: 4004kb
input:
5000 182682143490 2141200490 491474481633 645870617005 614391945875 954662877791 999999906824 999999986402 559562261622 999999929779 999999837149 999999646265 268454415317 999999171756 999998932364 199960439797 999998396909 823161202351 999997819513 999997527560 999997171707 999996774679 99999635828...
output:
772519397
result:
ok "772519397"
Test #13:
score: 0
Accepted
time: 3ms
memory: 3968kb
input:
5000 304953313333 975183464755 999999958493 999999945958 999999881001 999999736301 999999530494 999999307991 999999043312 999998689969 999998335878 999997901831 999997374056 999996845656 999996308684 999995746014 999995094383 999994379229 999993613721 999992821801 999991974425 999991110674 999990235...
output:
958370949
result:
ok "958370949"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3988kb
input:
5000 50131007849 513993519329 977855960409 999999975589 622431075835 999999990868 999999906828 999999744279 999999518233 187974338728 180142660520 999998771957 713085937291 999998273915 999997939102 999997566488 999997134505 999996637890 999996129423 999995546872 999994913628 901973523223 9999935935...
output:
220313865
result:
ok "220313865"
Test #15:
score: 0
Accepted
time: 4ms
memory: 3796kb
input:
5000 38913877553 72568444743 12600004417 272523691307 345169412783 159626587707 488665865251 584003425571 661873323451 739743122924 773411128961 579455320551 973352516913 999999947063 898832460426 999999964367 703399657201 999999956182 999999943332 999999895232 374192348094 999999746669 999999613113...
output:
912109210
result:
ok "912109210"
Test #16:
score: 0
Accepted
time: 3ms
memory: 3936kb
input:
5000 500661178996 830606330068 999999921730 76046992909 249966831793 282428933075 999999991226 93093616510 999999930539 21269407067 999999800994 999999669698 612121846360 999999406753 999999223563 490349993172 999998812585 999998577614 258179270664 650221614792 162500641022 971620612638 999997337229...
output:
225949849
result:
ok "225949849"
Test #17:
score: 0
Accepted
time: 3ms
memory: 3948kb
input:
5000 96636495565 876047161291 999999956147 999999900455 999999794556 999999612795 999999384863 999999155919 291140890508 999998606064 999998251199 999997849934 999997448584 999996976405 999996407086 999995775759 142179410415 999994497723 999993849860 999993125973 999992393850 999991648438 9999908168...
output:
198832401
result:
ok "198832401"
Test #18:
score: 0
Accepted
time: 4ms
memory: 3812kb
input:
5000 227759449377 215126601299 968436381497 659508059861 296154593126 532545255458 676283137624 793774420266 477847283648 819956929821 792474270670 520802101780 174728981654 983056401038 727300242200 486259514436 708418941287 517233349277 747191912062 900200265029 418004680115 984177617522 112319658...
output:
278159165
result:
ok "278159165"
Test #19:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
5000 105603061676 117969061792 291081695382 180373745978 21723680175 806080988657 139199046179 304207863135 243476309424 724313468929 426847434706 838703319594 577930725134 99458488055 140552822792 696044364803 914646688775 478029166434 707277758362 260042678686 216408897138 559581185451 86596293323...
output:
72656673
result:
ok "72656673"
Test #20:
score: 0
Accepted
time: 4ms
memory: 3872kb
input:
5000 555736355784 266680249447 703569450267 586944676139 125766689234 308190809501 316378705410 975350664246 48828558465 343812157125 877790944037 487432664541 130461582719 437502178175 385861000495 754964049757 745747792150 452231142690 660089861802 907788042612 243925387993 622329576773 4381244449...
output:
569702228
result:
ok "569702228"
Test #21:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
5000 471977958492 448476416347 929137668174 310019132092 687651931583 180163366400 318195889933 303594684297 816852542654 272730782167 121319886866 400179641200 164272615947 655398642577 417821403362 492682653186 608588573163 877609414908 756322866617 345606899484 650025925848 540441691899 895491350...
output:
704759823
result:
ok "704759823"