QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#85462 | #5657. Hungry Cow | zlt | 9.090909 | 2236ms | 325744kb | C++14 | 3.6kb | 2023-03-07 19:39:16 | 2023-03-07 19:40:20 |
Judging History
answer
// Problem: P9130 [USACO23FEB] Hungry Cow P
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P9130
// Memory Limit: 512 MB
// Time Limit: 6000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define f(l, r) (((l + r) % mod) * ((r - l + 1) % mod) * inv2 % mod)
#define pb emplace_back
#define fst first
#define scd second
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 100100;
const ll N = (ll)1.2e15;
const ll mod = 998244353;
const ll inv2 = (mod + 1) / 2;
bool test1;
int n, ls[maxn * 150], rs[maxn * 150], ntot, rt[maxn];
ll ans[maxn];
vector<pii> vc[maxn << 2];
struct node {
ll val, cnt;
bool tag;
} tree[maxn * 150];
bool test2;
void pushup(int x, ll l, ll r) {
if (tree[x].tag) {
tree[x].cnt = r - l + 1;
tree[x].val = f(l, r);
} else {
tree[x].cnt = tree[ls[x]].cnt + tree[rs[x]].cnt;
tree[x].val = (tree[ls[x]].val + tree[rs[x]].val) % mod;
}
}
int update(int rt, ll l, ll r, ll ql, ll qr) {
int u = ++ntot;
ls[u] = ls[rt];
rs[u] = rs[rt];
tree[u] = tree[rt];
if (ql <= l && r <= qr) {
tree[u].tag = 1;
tree[u].cnt = r - l + 1;
tree[u].val = f(l, r);
return u;
}
ll mid = (l + r) >> 1;
if (ql <= mid) {
ls[u] = update(ls[u], l, mid, ql, qr);
}
if (qr > mid) {
rs[u] = update(rs[u], mid + 1, r, ql, qr);
}
pushup(u, l, r);
return u;
}
ll query(int rt, ll l, ll r, ll ql, ll qr, int fl = 0) {
if (!rt) {
return fl ? min(qr, r) - max(ql, l) + 1 : 0;
}
fl |= tree[rt].tag;
if (ql <= l && r <= qr) {
return (fl ? r - l + 1 : tree[rt].cnt);
}
ll mid = (l + r) >> 1, res = 0;
if (ql <= mid) {
res += query(ls[rt], l, mid, ql, qr, fl);
}
if (qr > mid) {
res += query(rs[rt], mid + 1, r, ql, qr, fl);
}
return res;
}
ll find(int rt, ll l, ll r, ll x, int fl = 0) {
if (!rt) {
return l + x - 1;
}
if (l == r) {
return l;
}
fl |= tree[rt].tag;
ll mid = (l + r) >> 1;
ll tmp = (fl ? 0 : mid - l + 1 - tree[ls[rt]].cnt);
return x <= tmp ? find(ls[rt], l, mid, x, fl) : find(rs[rt], mid + 1, r, x - tmp, fl);
}
void insert(int rt, int l, int r, int ql, int qr, pii x) {
if (ql <= l && r <= qr) {
vc[rt].pb(x);
return;
}
int mid = (l + r) >> 1;
if (ql <= mid) {
insert(rt << 1, l, mid, ql, qr, x);
}
if (qr > mid) {
insert(rt << 1 | 1, mid + 1, r, ql, qr, x);
}
}
void dfs(int u, int l, int r) {
int lsttot = ntot;
rt[u] = rt[u >> 1];
for (pii p : vc[u]) {
ll pos = find(rt[u], 1, N, p.scd + p.fst - 1 - query(rt[u], 1, N, 1, p.fst - 1));
rt[u] = update(rt[u], 1, N, p.fst, pos);
}
if (l == r) {
ans[l] = tree[rt[u]].val;
} else {
int mid = (l + r) >> 1;
dfs(u << 1, l, mid);
dfs(u << 1 | 1, mid + 1, r);
}
for (int i = lsttot + 1; i <= ntot; ++i) {
ls[i] = rs[i] = 0;
tree[i].val = tree[i].cnt = tree[i].tag = 0;
}
ntot = lsttot;
}
void solve() {
scanf("%d", &n);
map<ll, pii> mp;
for (int i = 1; i <= n; ++i) {
ll x, y;
scanf("%lld%lld", &x, &y);
if (mp.find(x) != mp.end()) {
insert(1, 1, n, mp[x].scd, i - 1, make_pair(x, mp[x].fst));
}
mp[x] = make_pair(y, i);
}
for (auto p : mp) {
insert(1, 1, n, p.scd.scd, n, make_pair(p.fst, p.scd.fst));
}
dfs(1, 1, n);
for (int i = 1; i <= n; ++i) {
printf("%lld\n", ans[i]);
}
}
int main() {
fprintf(stderr, "%.2lf MB\n", (&test2 - &test1) / 1048576.);
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 4.54545
Accepted
time: 3ms
memory: 13120kb
input:
3 4 3 1 5 1 2
output:
15 36 18
result:
ok 3 number(s): "15 36 18"
Test #2:
score: 4.54545
Accepted
time: 3ms
memory: 13048kb
input:
9 1 89 30 7 101 26 1 24 5 1 60 4 5 10 101 0 1 200
output:
4005 4656 7607 3482 3507 3753 4058 1107 24531
result:
ok 9 numbers
Test #3:
score: 0
Wrong Answer
time: 39ms
memory: 24336kb
input:
5000 1 255364995 414918035 212844 1 112266691 321122438 191414 1 277615842 848755093 61676 1 432591689 892259443 53755 1 263753018 173404455 173565 1 178341924 878941367 221276 1 65332960 439468128 240741 1 812238377 191076090 108732 1 180383041 927440330 112995 1 595696140 579818784 85614 1 5057816...
output:
996800190 711403349 280121496 -388582458 560282935 666545784 14672130 80470397 -458542034 -252131129 -891073054 -45256173 539996644 387265994 24829568 141343219 -440919201 111086844 724003009 454959152 937585337 803175963 160952371 266808252 -252654974 -384325033 480502583 573682902 524666854 763846...
result:
wrong answer 1st numbers differ - expected: '235118030', found: '996800190'
Test #4:
score: 0
Wrong Answer
time: 1414ms
memory: 325744kb
input:
100000 1 500000000 1000000001 500000000 2000000001 500000000 3000000001 500000000 4000000001 500000000 5000000001 500000000 6000000001 500000000 7000000001 500000000 8000000001 500000000 9000000001 500000000 10000000001 500000000 11000000001 500000000 12000000001 500000000 13000000001 500000000 1400...
output:
111994564 -69490139 -210536244 -780955744 289504586 665821749 -253093950 196528333 282969664 -844485272 -471017340 -659307689 -278727080 -459904752 -6019023 -246276461 -50047827 -390646878 -162374971 -495861345 -459054090 -917812673 -873892741 -393486737 -474839014 -919372243 -927419400 -366595599 -...
result:
wrong answer 1st numbers differ - expected: '375000007', found: '111994564'
Test #5:
score: 0
Wrong Answer
time: 2236ms
memory: 213832kb
input:
100000 49998999950002 500000000 49997999950003 500000000 49996999950004 500000000 49995999950005 500000000 49994999950006 500000000 49993999950007 500000000 49992999950008 500000000 49991999950009 500000000 49990999950010 500000000 49989999950011 500000000 49988999950012 500000000 49987999950013 500...
output:
-364298374 -731275263 -102686314 457031677 214404129 -30901934 -212694069 402502305 82968254 -106859426 -166980735 -428357888 438215683 237673943 166838574 27132247 -181445038 -194123509 -209480495 -293708439 -314422455 -337814986 -363886032 -392635593 507988241 -391977817 -362570480 -203456772 -245...
result:
wrong answer 1st numbers differ - expected: '376399979', found: '-364298374'
Test #6:
score: 0
Wrong Answer
time: 1931ms
memory: 303016kb
input:
100000 92303348842417 121458 92270522994821 852054850 93765096269940 752161890 97779083359973 984327853 90030769679569 439157849 99462493683485 45660 95578441605501 614317411 92236129196525 474149928 96065411631989 429943696 90394247621798 382840249 89263934750729 791122796 93577089467158 99679481 9...
output:
-17913717 -42998384 -682420136 288035070 437937906 869209503 942760650 379516302 -110935856 -552400311 -646216001 52487680 -265632667 432048535 -83570121 -457156959 -154664602 598423382 475451553 32743862 636349589 971357138 85318091 -186987152 72799814 -74161316 -248138904 -241427683 81070802 -3278...
result:
wrong answer 1st numbers differ - expected: '601385635', found: '-17913717'
Test #7:
score: 0
Wrong Answer
time: 1932ms
memory: 303240kb
input:
100000 98001410246890 641673458 94816407430628 495030536 95979591652947 43208 95979591652947 183686 97163521776290 904784415 91640049592559 875129980 95914835187460 844802426 94846379383324 974270031 99639652388956 311664277 99298294827771 913614463 99476866913169 221766107 97248342663994 669489020 ...
output:
25861029 -72099092 -456431784 -611353079 -221376062 -853749703 -935101270 -83597526 -421582373 -881007342 -943750622 -330733954 -42424212 -861262201 -352245740 -319655445 -55334050 -650776352 -892436262 -828323100 -163239625 -509249669 -545577570 -205965284 -539193012 -201838016 -435417303 -20070624...
result:
wrong answer 1st numbers differ - expected: '805408268', found: '25861029'
Test #8:
score: 0
Wrong Answer
time: 1807ms
memory: 303816kb
input:
100000 97338601145206 191999210 97657969728741 875988993 92559675348135 8552565 99354409480201 960853995 93648768326445 343671323 97400841247229 104463842 98844341051398 508718383 96144328794112 187050711 98030257583732 365513 92378049740181 852725611 98301676983212 360931360 99458914124366 80234576...
output:
-570318465 -580342949 -249982736 255487132 -386112415 -857959476 -104502412 191512517 130821481 13971296 -231172238 -145140796 -80675614 1971604 -7086713 196945508 571375592 430706557 19259875 -6549499 255569447 68109526 593650520 93049193 113663811 557534359 862712496 59314243 803406043 832281263 6...
result:
wrong answer 1st numbers differ - expected: '201835835', found: '-570318465'
Test #9:
score: 0
Wrong Answer
time: 1931ms
memory: 304660kb
input:
100000 96119987448606 658315028 98644701118435 280992389 98180676447908 56168 99822794299596 237183170 94655838918825 563695131 95744558879343 686204820 93739311062176 263266841 97630990881452 96901680 98683433984282 380708175 98141920320037 147598812 98095513966598 814629225 97882900659205 55097258...
output:
-311988508 -105454593 -256472260 498318127 853966125 257599193 -198244413 -361230176 406355394 424468196 227578204 -181643368 -511109645 -118709154 -77137356 -100553587 65660492 -455920496 -125517703 -253139662 -497169428 -955413437 -244070557 -156088015 -282742992 -468644944 -115640226 -922165411 -...
result:
wrong answer 1st numbers differ - expected: '284288958', found: '-311988508'
Test #10:
score: 0
Wrong Answer
time: 2004ms
memory: 304768kb
input:
100000 98169641631056 170946511 99452522210742 393032132 98797460964704 393706377 98747209012224 529219651 99152468691953 362194103 99410753036475 215295 97096873124809 1315725 96106202009957 124516158 95176405230280 853965254 99359463136784 622839995 96635771520630 550456203 96368792029394 93630831...
output:
-877472322 -376306602 -419482822 -161162368 -200139018 -745436921 -528437860 -575240388 -64880465 -733029175 -130393883 -949176640 -487087469 208429923 -153248650 588195563 198066563 382044153 658102377 681826058 913238472 613972962 209922616 963476681 -16587598 260673666 -53074704 -283952993 -68797...
result:
wrong answer 1st numbers differ - expected: '692991104', found: '-877472322'
Test #11:
score: 0
Wrong Answer
time: 1693ms
memory: 296616kb
input:
100000 97499080763005 475255826 97499083333242 9347 97499080763005 395470349 97499924236501 4654 97499080763005 148122052 97499213182916 2365 97499080763005 544025506 97499777050346 9912 97499080763005 41736833 97499401163067 12607 97499080763005 127843558 97499125181305 7144 97499080763005 13152858...
output:
207216106 228112074 -631608022 -21707845 19505683 115722490 -408928353 232808657 307015479 -515032156 -367369145 -145467466 51894200 40500232 -652552795 -151365548 75279447 -508067162 -592569128 -71114207 -451903710 -394797797 -304884864 -479301542 -222719747 -268012933 -522193599 275139567 -8755312...
result:
wrong answer 1st numbers differ - expected: '655956691', found: '207216106'
Test #12:
score: 0
Wrong Answer
time: 1515ms
memory: 253268kb
input:
100000 98999026537234 929244389 98999182418499 5182 98999026537234 774643967 98999646433835 17857 98999026537234 760743518 98999980664456 7597 98999026537234 573421161 98999090975969 6621 98999026537234 95191521 98999947586610 17798 98999026537234 953104244 98999116462517 15643 98999026537234 100617...
output:
111222644 474797859 791875410 941416719 182817592 171805056 38316554 539538247 491596575 224500146 570161473 543842172 147736534 962027387 563296361 295545355 22299987 892349253 158127202 15978195 147631211 506131595 647772868 75497251 966081855 742537199 115267746 970100902 323920932 464108941 6365...
result:
wrong answer 1st numbers differ - expected: '526240962', found: '111222644'
Test #13:
score: 0
Wrong Answer
time: 1557ms
memory: 249324kb
input:
100000 99499024212061 630391525 99499061152079 3864 99499024212061 16505706 99499878275777 4812 99499024212061 776185964 99499757280269 12059 99499024212061 356565635 99499399237611 8902 99499024212061 972528120 99499256994518 9171 99499024212061 419476867 99499909552451 17146 99499024212061 6767939...
output:
896993256 221563030 192314524 366078476 417890895 872751355 -668186734 27315910 -1997906 473767078 -233766303 18694107 238533662 670153439 506574769 862243642 241867230 717288783 201821602 716082519 810839760 519250677 719046405 807337350 586785418 780284265 304275202 164533741 481086493 83660214 14...
result:
wrong answer 1st numbers differ - expected: '358833000', found: '896993256'
Test #14:
score: 0
Wrong Answer
time: 2104ms
memory: 190248kb
input:
99999 10490328589436 1000000000 13762508396295 1000000000 40632115714511 1000000000 32834989282081 1000000000 29091918306598 1000000000 24352818172350 1000000000 23447797352860 1000000000 38073075086135 1000000000 14288530509239 1000000000 36463049009868 1000000000 10562334120356 1000000000 34490016...
output:
-504314441 -797332932 -655263200 -799502008 -814873939 -954758395 -567105684 -514234743 -89814294 -265732184 -581405078 -683764332 -670230806 -174282168 36687292 17319821 -204563653 -735025944 57202455 -110481774 -898373290 -683705802 -945349756 -545685917 -469516193 -253747265 -145312365 699994331 ...
result:
wrong answer 1st numbers differ - expected: '700388007', found: '-504314441'
Test #15:
score: 0
Wrong Answer
time: 2071ms
memory: 185648kb
input:
99999 61585049539216 1000000000 58981995705940 1000000000 44247484521936 1000000000 70916218483207 1000000000 47696673638497 1000000000 60781033156530 1000000000 55859922511212 1000000000 59143999312357 1000000000 57175954090596 1000000000 71328224891428 1000000000 46047599292678 1000000000 47510666...
output:
150440545 105732624 156219415 -96518174 185140877 990183602 129621988 68905359 -525144691 -627943687 -7041403 439442408 875662933 845941029 638709891 649496187 794241620 273472609 429625855 417724254 347485365 -186851861 591495339 227997731 884144152 544302312 843672496 974515512 737870462 190054898...
result:
wrong answer 1st numbers differ - expected: '656243188', found: '150440545'
Test #16:
score: 0
Wrong Answer
time: 2041ms
memory: 185432kb
input:
99999 21219982576425 1000000000 42260400232639 1000000000 26412110792985 1000000000 11035481121988 1000000000 13219690258669 1000000000 19550933913223 1000000000 32679237390903 1000000000 15679803374289 1000000000 23896051833122 1000000000 20099950455987 1000000000 14778766729432 1000000000 21547991...
output:
739547253 -91910522 -65786166 -314163776 -153016521 -439499813 28292642 -614286461 -370260123 21457702 8164754 -326259212 -256565999 -719562656 -714622989 -644537674 -66339972 -836562631 -715785943 -882073641 -989995902 -73735994 -234541804 225031619 -285861173 -209268517 -360568526 188165153 283466...
result:
wrong answer 1st numbers differ - expected: '123004833', found: '739547253'
Test #17:
score: 0
Wrong Answer
time: 2031ms
memory: 182040kb
input:
99999 28503598869279 1000000000 32397709666940 1000000000 25833502058723 1000000000 38020841213328 1000000000 54560138759501 1000000000 42230929758874 1000000000 28972613620824 1000000000 28498598787317 1000000000 54070131397843 1000000000 22084267818956 1000000000 37776835952805 1000000000 44465973...
output:
42825854 -47898664 335249888 117963568 -633826959 -200582284 370572292 96297293 244766203 -685051625 82849301 -567970892 -963144287 -720441663 -16693279 436653539 785170382 147835100 642212419 -266839932 -99103509 -60249605 470389819 283347219 312405915 134813844 375315705 -152440336 320941888 37137...
result:
wrong answer 1st numbers differ - expected: '809311757', found: '42825854'
Test #18:
score: 0
Wrong Answer
time: 2137ms
memory: 187288kb
input:
99999 18175781548542 1000000000 40883228277118 1000000000 33828113807745 1000000000 17817771477758 1000000000 22749897023579 1000000000 18015777423352 1000000000 28920025506062 1000000000 18799798298070 1000000000 27979006765970 1000000000 17103749421004 1000000000 24329932307643 1000000000 29798042...
output:
-155397927 -184625525 616185954 265598325 -290817052 -137116497 -618169147 -992196954 -226863881 -586908722 -213959140 -436851594 -711074536 -627030109 -138541873 -83325023 -633638443 -835930394 -907866303 -96400238 -461316201 -370615748 -249759272 -503662224 -243378291 -320971167 -751638829 -495739...
result:
wrong answer 1st numbers differ - expected: '530050851', found: '-155397927'
Test #19:
score: 0
Wrong Answer
time: 2160ms
memory: 181024kb
input:
99999 13631696063382 1000000000 19095823575649 1000000000 18048800926387 1000000000 17060779354093 1000000000 15768748767399 1000000000 30886037572930 1000000000 26814970558482 1000000000 8165534157289 1000000000 27914989206121 1000000000 34170089895536 1000000000 27764986366439 1000000000 145187181...
output:
38819172 -752640275 -515857813 -784674093 -702961249 -766047488 -648221362 -744354757 -503347886 -721323778 -335139072 -216793854 189972860 -11385983 -750459150 -506706109 -392193945 -809657199 24051813 -479240615 -431091878 177795052 -206172111 -369904583 63761136 -422325523 -22842089 -48010291 254...
result:
wrong answer 1st numbers differ - expected: '128224308', found: '38819172'
Test #20:
score: 0
Wrong Answer
time: 2064ms
memory: 185368kb
input:
99999 71091006018203 1000000000 42267334298998 1000000000 53421686894439 1000000000 52992676205010 1000000000 49055576058012 1000000000 70721000416119 1000000000 43151374327143 1000000000 70716000332404 1000000000 51528640431406 1000000000 65945925001029 1000000000 39524135856472 1000000000 66414932...
output:
-375746844 -824389228 -987936452 -374197239 -412533723 -189565937 -3930893 -253397682 -12477248 -462303874 -188627327 -452917577 -287868346 -19120537 -854384284 -872715721 -362127455 -960564138 -915685925 -70449725 -650782484 -51450155 -734884653 -443964141 -903959772 -652076958 -189168201 -12436834...
result:
wrong answer 1st numbers differ - expected: '961356073', found: '-375746844'
Test #21:
score: 0
Wrong Answer
time: 2137ms
memory: 183584kb
input:
99999 43981987091230 1000000000 41793950053258 1000000000 23385527966154 1000000000 32049759202175 1000000000 48927065970165 1000000000 26694629471843 1000000000 27661655640242 1000000000 37241867113918 1000000000 49110069037684 1000000000 20323405372655 1000000000 43304975621086 1000000000 48021052...
output:
-173904626 -33454843 760771152 23779157 -376150555 530841204 -27938986 -259399509 70108060 651807211 751186340 475032444 98199241 -77354969 -69831535 -503417037 247208970 51378983 766794499 168160893 435011108 369770179 600932858 237695113 71408001 81362374 726763056 398443444 -348233905 311385237 -...
result:
wrong answer 1st numbers differ - expected: '92516536', found: '-173904626'
Test #22:
score: 0
Wrong Answer
time: 2097ms
memory: 184156kb
input:
99999 31159466866911 1000000000 28413414847308 1000000000 25948364344910 1000000000 31236468095715 1000000000 22036273821032 1000000000 24056321657736 1000000000 36031551606814 1000000000 37935581367999 1000000000 40624624246259 1000000000 18857191994835 1000000000 22179277697755 1000000000 29154428...
output:
-448992975 -60892686 397353533 251857932 594786024 -114883223 -383158182 -48299835 145367920 528253847 481661855 364042304 679018979 587260742 497201641 427529877 620226585 -46943279 -504929172 43589568 299489777 82572261 -129155771 -213873083 -297191455 -468807952 -157526217 29680269 302036725 -453...
result:
wrong answer 1st numbers differ - expected: '733458470', found: '-448992975'