QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#522385 | #7043. Image Processing | wxy | AC ✓ | 248ms | 30984kb | C++17 | 2.0kb | 2024-08-16 22:07:53 | 2024-08-16 22:07:53 |
Judging History
answer
#include <bits/stdc++.h>
namespace Main {
const int N = 1e6 + 5;
int n,k,a[N],f[N];
struct data_struct_minv {
int fa[N],stack[N],top;
int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
void init() {
for (int i = 1; i <= n; i++)
fa[i] = i;
}
void insert(int x) {
while (top && a[stack[top]] >= a[x]) {
fa[stack[top]] = x, -- top;
}
stack[++ top] = x;
}
int calc(int x) {
return a[get(x)];
}
} minv;
struct data_struct_maxv {
int fa[N],stack[N],top;
int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
void init() {
for (int i = 1; i <= n; i++)
fa[i] = i;
}
void insert(int x) {
while (top && a[stack[top]] <= a[x]) {
fa[stack[top]] = x, -- top;
}
stack[++ top] = x;
}
int calc(int x) {
return a[get(x)];
}
} maxv;
int stack[N],top;
void insert(int x) {
while (top && f[stack[top]] >= f[x]) {
-- top;
}
stack[++ top] = x;
}
void main() {
scanf("%d%d",&n,&k);
insert(0);
minv.init(), maxv.init();
for (int i = 1; i <= n; i++) {
scanf("%d",&a[i]);
a[i] ^= f[i - 1];
minv.insert(i), maxv.insert(i);
if (i < k) {
printf("%d\n",0);
continue;
}
if (i - k >= k)
insert(i - k);
if (top == 1) {
f[i] = maxv.calc(1) - minv.calc(1);
printf("%d\n",f[i]);
continue;
}
int low = 1, high = top;
while (low < high) {
int mid = (low + high + 1) >> 1;
if (f[stack[mid]] <= maxv.calc(stack[mid] + 1) - minv.calc(stack[mid] + 1))
low = mid;
else
high = mid - 1;
}
f[i] = maxv.calc(stack[low] + 1) - minv.calc(stack[low] + 1);
if (low + 1 <= top)
f[i] = std::min(f[i],f[stack[low + 1]]);
printf("%d\n",f[i]);
}
}
}
signed main() {
Main::main();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14212kb
input:
5 2 50 110 190 120 34
output:
0 60 80 90 80
result:
ok 5 number(s): "0 60 80 90 80"
Test #2:
score: 0
Accepted
time: 182ms
memory: 23944kb
input:
1000000 7 740760744 128949015 864430306 803157027 867410355 348411907 788815333 62537628 989888355 897434632 893725957 385915358 116671606 91645858 585889989 81062060 177182250 543069056 107482294 981936827 433021299 764779421 730485811 37353026 476269126 318260875 564753383 841579792 652031776 3016...
output:
0 0 0 0 0 0 738461340 738461340 738461340 738461340 738461340 861209643 861209643 738461340 739549417 739549417 739549417 783969241 783969241 783969241 738461340 904097193 904097193 910753514 910753514 910753514 910753514 910753514 904097193 904097193 904097193 904097193 904097193 904097193 90409719...
result:
ok 1000000 numbers
Test #3:
score: 0
Accepted
time: 177ms
memory: 23956kb
input:
1000000 106 718106353 957103229 178679497 30122152 539392262 967694986 411843264 878332932 304891280 49993165 575798961 112319481 929328366 408264344 69150964 860984775 852441333 611859467 307742908 777689983 835915923 680677321 283125322 870857035 73680192 903946994 345887196 671045189 390601447 92...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 973002280 973002280 973002280 973002280 973002280 973731513 973731513 973731513 973731513 ...
result:
ok 1000000 numbers
Test #4:
score: 0
Accepted
time: 174ms
memory: 24036kb
input:
1000000 638 192463945 702134958 345542618 669865830 85855398 439488356 311123607 983422443 824130032 482375875 82888112 834016258 434451960 842325416 278600378 970131765 191089971 973830613 676858689 16912555 889301644 195308390 8838132 65590862 91160693 10485363 565917834 867947180 403081242 995642...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #5:
score: 0
Accepted
time: 181ms
memory: 23992kb
input:
1000000 4419 766757907 691258997 943689588 724926794 873612124 655942731 622247010 127393979 566689614 916397853 129170439 351371578 395010700 362176313 144517148 334931535 997357717 866472973 141659563 230674896 754534513 915060959 784926145 24412372 17940633 506638086 568637474 674497801 972536484...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #6:
score: 0
Accepted
time: 169ms
memory: 23844kb
input:
1000000 15252 482549745 234451363 379198395 186404152 746970639 99618958 954628472 864867575 609040514 853026700 88647190 400589742 756951366 226001929 346217977 249948293 755539806 996608570 767720589 187525639 705337860 968784962 806623701 413357199 781068200 120489841 202517850 986199359 63965896...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #7:
score: 0
Accepted
time: 173ms
memory: 23600kb
input:
1000000 90363 331128761 509207949 860935618 851737770 12782945 265991521 159033465 230755590 575795471 302069501 735319593 397331166 215596429 944601335 38654297 283607457 871187280 284970611 144750064 165814817 565050266 902545684 915339326 600166122 608673261 386967346 379027093 317636179 18468832...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #8:
score: 0
Accepted
time: 146ms
memory: 22764kb
input:
1000000 292559 549452146 479848976 745070445 686754013 198234287 555646589 3702198 545375873 109081524 521400181 997751872 59430741 554115035 141720157 286973665 832701708 71078753 80672658 127375045 490357270 559098464 237998960 960880460 786418982 915726177 377843147 691025264 505678474 566734492 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #9:
score: 0
Accepted
time: 121ms
memory: 21760kb
input:
1000000 842683 804705631 784851530 965586737 932753417 610081636 117512791 290609699 504073783 872348051 255149211 835276223 1083447 476842452 388950379 919714488 573152620 521775903 735763770 614664766 543670272 818280871 739342184 620269431 644733508 9002030 766968524 366696221 557442098 492658493...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #10:
score: 0
Accepted
time: 248ms
memory: 26852kb
input:
1000000 26281 502 1005 1501 2002 2504 3004 3504 4004 4502 5003 5501 6004 6502 7003 7502 8004 8504 9001 9504 10005 10504 11004 11504 12001 12504 13003 13501 14005 14504 15001 15502 16002 16504 17005 17503 18003 18504 19003 19502 20005 20504 21001 21502 22001 22504 23005 23504 24002 24503 25003 25505 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #11:
score: 0
Accepted
time: 244ms
memory: 26312kb
input:
1000000 20050 500000004 499999502 499999004 499998504 499998005 499997505 499997003 499996502 499996003 499995504 499995005 499994504 499994003 499993501 499993005 499992501 499992003 499991503 499991001 499990505 499990004 499989503 499989005 499988504 499988001 499987502 499987004 499986504 499986...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #12:
score: 0
Accepted
time: 147ms
memory: 30984kb
input:
1000000 237280 501 1004 1504 2004 2502 3003 3504 4005 4505 5004 5502 6002 6505 7004 7501 8001 8502 9005 9501 10003 10505 11005 11503 12001 12501 13004 13502 14004 14501 15001 15503 16005 16504 17002 17503 18005 18505 19002 19503 20004 20502 21002 21504 22002 22502 23003 23501 24003 24502 25005 25504...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #13:
score: 0
Accepted
time: 150ms
memory: 29608kb
input:
1000000 223556 504 1002 1501 2004 2501 3003 3503 4002 4505 5005 5504 6001 6504 7003 7503 8005 8501 9001 9505 10003 10504 11002 11503 12005 12502 13002 13502 14004 14502 15003 15503 16005 16503 17001 17503 18002 18502 19004 19504 20002 20501 21004 21501 22001 22504 23004 23504 24002 24503 25004 25505...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers