QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85468 | #5657. Hungry Cow | zlt | 9.090909 | 2235ms | 325648kb | C++14 | 3.6kb | 2023-03-07 19:42:01 | 2023-03-07 19:42:18 |
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 = 1000000007;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4.54545
Accepted
time: 1ms
memory: 13060kb
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: 4ms
memory: 13092kb
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: 42ms
memory: 24340kb
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:
-403081143 -783714998 -431941513 264974338 -321200945 -31282444 820915745 634859109 -228667513 -416433249 529985833 721786144 -207757161 -141451441 218444929 594169908 714079885 476022851 257446500 350746171 830167660 531050025 745359290 584406740 -127305431 9963963 13684963 928373595 266405255 5084...
result:
wrong answer 1st numbers differ - expected: '235118030', found: '-403081143'
Test #4:
score: 0
Wrong Answer
time: 1465ms
memory: 325648kb
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:
247940715 995881458 661478214 244730990 910327802 240612637 906209498 907118371 572715274 -514655792 733285175 63570157 311511166 59452196 142705245 561270313 391555421 721840557 716813723 882410899 130352097 625325340 620298604 950583887 451493173 452402487 865031848 195317222 696226613 608856044 5...
result:
wrong answer 1st numbers differ - expected: '375000007', found: '247940715'
Test #5:
score: 0
Wrong Answer
time: 2200ms
memory: 213860kb
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:
-262284136 846677849 509169362 -39437019 294862160 765034882 188797712 583746083 514628570 746072609 948702182 269609872 -38236324 -627864976 -81620078 253526926 142203465 149158128 874330342 570688083 220635939 171145347 492900869 368185926 452890821 -16463 -81677633 137222749 327308665 53328697 -5...
result:
wrong answer 1st numbers differ - expected: '376399979', found: '-262284136'
Test #6:
score: 0
Wrong Answer
time: 1844ms
memory: 302988kb
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:
-131071363 -584005280 -291278909 -476565575 -429906726 -631817464 -571705220 -567285301 -582562741 -502444966 -630480754 -904072439 -772746732 -330645973 -115813811 -678442862 -626729566 -47494878 -600713429 -284405427 -763913985 -839147006 -763308118 -552782146 -46743747 210757908 8096709 -13134122...
result:
wrong answer 1st numbers differ - expected: '601385635', found: '-131071363'
Test #7:
score: 0
Wrong Answer
time: 1931ms
memory: 303204kb
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:
643672058 718648917 723750909 -227052716 -258999596 -97873657 107547947 754811607 522054887 272537989 -134436123 -579332373 -559413435 -622193753 -221491708 13961397 343934992 605739643 -139184928 -2027689 -465560799 -234112302 -601635963 -82576294 181839965 -336461497 -47393578 -165322168 -55922111...
result:
wrong answer 1st numbers differ - expected: '805408268', found: '643672058'
Test #8:
score: 0
Wrong Answer
time: 2050ms
memory: 303812kb
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:
230100686 -670447429 -932609185 -510616178 -9793015 -67541190 -211851324 -851959065 -129320196 -450825648 -742627109 -672109051 84048877 -125142165 -719471381 111402671 784429250 222651874 140809393 79248729 847724858 873809490 7932409 971035061 530785603 948859443 48350510 613559853 798094245 17745...
result:
wrong answer 1st numbers differ - expected: '201835835', found: '230100686'
Test #9:
score: 0
Wrong Answer
time: 1952ms
memory: 304704kb
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:
-216187054 28763208 175926298 476621322 -256232821 308377623 444948106 -99437761 -185728468 2006197 419490589 14328571 -560569800 -397266875 -282504249 -266957921 46108814 -113014603 -23639005 -24405852 169593504 -495880181 -685312747 -292912244 499975844 -223917484 -293012974 -335161205 330502064 1...
result:
wrong answer 1st numbers differ - expected: '284288958', found: '-216187054'
Test #10:
score: 0
Wrong Answer
time: 1986ms
memory: 304708kb
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:
351142566 890356959 750375580 72612940 950044980 709889771 224231280 -248976626 -92211256 -716435991 74404565 -204486729 -974317076 -323335865 -88342286 -39095109 -60872197 -124241188 -119774708 -104624817 -954827 763216792 -60694148 378915980 708391441 792450328 231236867 -224323767 -474144343 1103...
result:
wrong answer 1st numbers differ - expected: '692991104', found: '351142566'
Test #11:
score: 0
Wrong Answer
time: 1721ms
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:
935061213 401822581 762866896 265553152 679827473 933468524 825675701 463643098 115855745 73965670 950200115 864515246 278420416 771815109 24687889 604969370 523919828 199226995 612924197 418775455 413510762 402063433 886305149 562964382 136699021 32711580 970933576 433824504 494445687 201466614 676...
result:
wrong answer 1st numbers differ - expected: '655956691', found: '935061213'
Test #12:
score: 0
Wrong Answer
time: 1573ms
memory: 253300kb
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:
-43018080 -718036597 32825899 140513222 -397517737 -829624814 -554792631 -144408366 514902273 495489480 -352834242 188929215 389922765 121800648 -594099406 -253662655 -715458926 -273411878 -399620015 -20437945 -87703107 434773232 245026525 836397989 -46248026 10161598 -974009467 -456926063 329887841...
result:
wrong answer 1st numbers differ - expected: '526240962', found: '-43018080'
Test #13:
score: 0
Wrong Answer
time: 1463ms
memory: 249256kb
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:
-329250828 -259805972 696593266 132285195 6049724 168975529 18909351 61486550 67305822 841129527 610110305 -289480323 707092849 328410239 290263843 924406677 972757946 18760929 398032812 755588349 641061464 336080494 95693084 170987314 -82129707 390294321 89475184 183854003 136012396 959054072 93350...
result:
wrong answer 1st numbers differ - expected: '358833000', found: '-329250828'
Test #14:
score: 0
Wrong Answer
time: 2119ms
memory: 190296kb
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:
-544030596 -779372249 -509114575 153711466 244326201 255847870 157875428 -333490425 -786270459 -301774522 -672379084 -349299661 63478905 26786918 -593614258 -98344303 -32569078 -250787 230058604 660758613 88077069 291966723 113594923 352711194 -351487780 -862189803 -16516533 -336952160 -324736017 -3...
result:
wrong answer 1st numbers differ - expected: '700388007', found: '-544030596'
Test #15:
score: 0
Wrong Answer
time: 2124ms
memory: 185692kb
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:
-213036307 -234407697 -181562025 -918963121 -902686407 -805695384 -138328584 -324021882 -318964928 -288598510 -209043065 -273600821 -357566219 -433794576 -418625359 -217908222 -524109173 -41270037 -406425234 -741310975 -701147408 -991773961 -409432467 -514402278 -987242801 -755453422 -635869087 -967...
result:
wrong answer 1st numbers differ - expected: '656243188', found: '-213036307'
Test #16:
score: 0
Wrong Answer
time: 2143ms
memory: 185352kb
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:
324720854 88819953 -108615698 -600113486 -51281602 -580293775 -73891143 -576146039 131518150 -122316504 -538531153 -920579520 -621545798 -945675489 -494282981 -523973347 -904337239 -50528950 -128570567 207278280 -317285297 -299201013 419991957 813680107 402619835 -54375859 -350878405 -355751872 -452...
result:
wrong answer 1st numbers differ - expected: '123004833', found: '324720854'
Test #17:
score: 0
Wrong Answer
time: 2069ms
memory: 181992kb
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:
-331557559 -70920635 -85967668 388927446 346271786 183790737 247442428 275134483 -18250950 866505952 899294610 108158747 998552867 201474346 922866037 386817276 619622415 307479882 522943890 116628114 -637614715 171885080 144629589 -210494471 -90149723 376583296 -304172932 -320179479 71311185 207598...
result:
wrong answer 1st numbers differ - expected: '809311757', found: '-331557559'
Test #18:
score: 0
Wrong Answer
time: 2167ms
memory: 187260kb
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:
75608567 -45715505 -176251383 -403490163 -823625940 -355684922 -179509189 -178118507 -247038404 -195095383 -109011717 -725848993 -317048901 -357653710 -249208127 -717460326 -121821379 -973244019 -429281135 -832148225 -820426870 -270829023 -146443072 -680794495 -645571342 -270366611 -785487115 -64112...
result:
wrong answer 1st numbers differ - expected: '530050851', found: '75608567'
Test #19:
score: 0
Wrong Answer
time: 2195ms
memory: 180944kb
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:
650199965 377834796 747425392 515687217 832793530 350559036 511324289 727477021 731539384 553499469 140270585 389324288 694394307 263368983 584877991 224911728 391127387 370017534 467223554 -142599156 -96542708 -718407894 -466528598 -192738699 373034815 -173257755 -232669702 -629364819 14422569 -118...
result:
wrong answer 1st numbers differ - expected: '128224308', found: '650199965'
Test #20:
score: 0
Wrong Answer
time: 2104ms
memory: 185428kb
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:
214502980 876523851 119658431 699588831 310548416 466043652 667170983 104508463 209174682 303794541 411859528 293910892 793739958 182320824 646926780 576107063 947292406 651392313 631313852 133058097 133188114 -421098604 -19631307 -962759744 -80872085 -253043766 -206774690 -306714806 -184538453 -900...
result:
wrong answer 1st numbers differ - expected: '961356073', found: '214502980'
Test #21:
score: 0
Wrong Answer
time: 2162ms
memory: 183564kb
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:
10462349 279416952 120010275 47704231 21294955 -420473410 -357954185 158465361 -12345651 935386811 209517744 99176700 107323036 312362159 623987411 732003863 20343858 931317240 721871206 972667982 373063441 364156730 763489996 37899358 464037780 615885670 952050652 4289841 523104947 800223573 945454...
result:
wrong answer 1st numbers differ - expected: '92516536', found: '10462349'
Test #22:
score: 0
Wrong Answer
time: 2235ms
memory: 184128kb
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:
103874600 352751195 -215616730 -702180099 -764495310 -473747535 -266272885 -488644475 222560975 340889619 566621605 482673791 479871384 371319180 -116587254 850978009 753494166 274004900 372306465 768335666 63473601 157617237 -635964412 282861922 414230795 655620933 487071031 790727839 204231762 709...
result:
wrong answer 1st numbers differ - expected: '733458470', found: '103874600'