QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#691138 | #6433. Klee in Solitary Confinement | LightFeather | TL | 8ms | 6960kb | C++20 | 1.3kb | 2024-10-31 10:04:50 | 2024-10-31 10:04:51 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
constexpr int N = 1e6 + 10;
int n, k;
int a[N];
vector<int> v[4 * N];
vector<PII> p[4 * N];
int mp[5 * N];
void solve(){
int ans = 1;
cin >> n >> k;
for(int i = 1; i <= n; i ++){
cin >> a[i];
a[i] += 2 * N;
mp[a[i]] ++;
ans = max(mp[a[i]], ans);
}
for(int i = 1; i <= n; i ++){
v[a[i]].push_back(-1);
v[a[i] + k].push_back(1);
}
if(!k){
cout << ans << endl;
return;
}
for(int i = 1; i <= n; i ++){
int j = a[i] + k;
int tot = v[j].size();
if(!tot)
continue;
ans = max(ans, mp[j] + v[j][0]);
vector<int> sum(tot + 1);
vector<int> summin(tot + 1);
sum[1] = v[j][0];
summin[1] = min(0ll, sum[1]);
for(int k = 2; k <= tot; k ++){
sum[k] = sum[k - 1] + v[j][k - 1];
summin[k] = min(summin[k - 1], sum[k]);
ans = max(ans, sum[k] - summin[k - 1] + mp[j]);
}
}
cout << ans << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while(t --)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 5612kb
input:
5 2 2 2 4 4 4
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 8ms
memory: 5552kb
input:
7 1 3 2 3 2 2 2 3
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 0
Accepted
time: 5ms
memory: 5704kb
input:
7 1 2 3 2 3 2 3 3
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 8ms
memory: 5836kb
input:
9 -100 -1 -2 1 2 -1 -2 1 -2 1
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 8ms
memory: 5632kb
input:
200 121649 0 527189 -1000000 -306471 -998939 527189 -1000000 -1000000 0 527189 0 527189 0 527189 -306471 -998939 -306471 -306471 -306471 0 0 527189 527189 1000000 527189 -1000000 1000000 648838 -1000000 -998939 -998939 -998939 0 1000000 -1000000 -998939 527189 1000000 648838 -1000000 1000000 648838 ...
output:
37
result:
ok 1 number(s): "37"
Test #6:
score: 0
Accepted
time: 8ms
memory: 5792kb
input:
200 -454379 -385892 454379 -1000000 373644 -665078 -1000000 -1000000 454379 0 1000000 373644 -1000000 1000000 -385892 -1000000 373644 0 -665078 0 -665078 -1000000 -665078 -385892 -665078 -385892 454379 -665078 -385892 -1000000 454379 1000000 -385892 373644 454379 -1000000 -385892 -1000000 -385892 -1...
output:
40
result:
ok 1 number(s): "40"
Test #7:
score: 0
Accepted
time: 8ms
memory: 5660kb
input:
200 0 451272 -1000000 677452 677452 0 18908 451272 677452 -233144 677452 451272 18908 -1000000 18908 -1000000 0 451272 0 -233144 677452 1000000 451272 1000000 18908 -1000000 0 -233144 451272 1000000 18908 677452 0 677452 0 677452 1000000 -233144 18908 451272 -1000000 -233144 18908 1000000 0 0 -23314...
output:
35
result:
ok 1 number(s): "35"
Test #8:
score: 0
Accepted
time: 4ms
memory: 5968kb
input:
200 -705945 -586687 198791 0 198791 0 705945 198791 -1000000 705945 705945 1000000 705945 0 -1000000 699023 0 705945 -586687 -1000000 198791 -1000000 1000000 198791 -1000000 198791 705945 -1000000 1000000 1000000 198791 198791 -1000000 699023 0 0 699023 -586687 705945 -586687 705945 699023 0 705945 ...
output:
34
result:
ok 1 number(s): "34"
Test #9:
score: 0
Accepted
time: 8ms
memory: 5656kb
input:
200 0 344286 0 -230711 532652 -589794 344286 532652 -1000000 -589794 344286 0 532652 -1000000 344286 344286 1000000 0 -1000000 532652 532652 532652 -230711 -1000000 344286 532652 532652 0 532652 1000000 0 0 1000000 -589794 -1000000 1000000 -1000000 -1000000 344286 0 344286 344286 1000000 -1000000 -1...
output:
34
result:
ok 1 number(s): "34"
Test #10:
score: 0
Accepted
time: 8ms
memory: 5928kb
input:
200 -230027 -1000000 -662604 0 1000000 59253 1000000 1000000 -662604 -662604 0 -70266 1000000 -300293 -300293 59253 1000000 -1000000 1000000 0 1000000 -662604 59253 -1000000 -70266 -1000000 -662604 -662604 59253 59253 -1000000 -70266 -70266 1000000 -300293 59253 59253 1000000 -70266 -1000000 -70266 ...
output:
33
result:
ok 1 number(s): "33"
Test #11:
score: 0
Accepted
time: 8ms
memory: 5688kb
input:
200 197410 1000000 -665711 0 -271800 -701554 -271800 -1000000 -665711 -665711 -1000000 -271800 1000000 -701554 1000000 -701554 -1000000 1000000 1000000 -1000000 -701554 1000000 -271800 -1000000 -197410 -665711 -701554 1000000 -1000000 -665711 -701554 -701554 -271800 -1000000 -1000000 -271800 -701554...
output:
37
result:
ok 1 number(s): "37"
Test #12:
score: 0
Accepted
time: 4ms
memory: 5780kb
input:
200 -96015 791544 -1000000 791544 -1000000 -668818 695529 1000000 -552146 -1000000 -668818 1000000 1000000 1000000 695529 695529 0 791544 -552146 0 1000000 791544 -668818 0 -1000000 0 -1000000 791544 -1000000 791544 1000000 791544 0 -1000000 0 -668818 695529 791544 1000000 695529 695529 -668818 -100...
output:
38
result:
ok 1 number(s): "38"
Test #13:
score: 0
Accepted
time: 8ms
memory: 5684kb
input:
200 -1000000 1000000 127969 0 0 0 -970611 0 0 293224 293224 293224 293224 -1000000 -970611 1000000 -1000000 820037 820037 820037 127969 127969 0 0 -970611 1000000 -970611 820037 -1000000 -970611 -1000000 820037 -970611 -1000000 127969 -970611 293224 1000000 293224 1000000 293224 293224 -1000000 8200...
output:
39
result:
ok 1 number(s): "39"
Test #14:
score: 0
Accepted
time: 4ms
memory: 5660kb
input:
200 0 0 527518 841746 0 331297 -1000000 595261 841746 527518 1000000 1000000 527518 1000000 527518 0 1000000 0 841746 527518 -1000000 595261 0 595261 -1000000 841746 841746 841746 0 -1000000 595261 331297 841746 0 841746 595261 0 595261 0 0 0 527518 331297 527518 0 841746 331297 0 1000000 -1000000 5...
output:
44
result:
ok 1 number(s): "44"
Test #15:
score: 0
Accepted
time: 8ms
memory: 5876kb
input:
200 -258363 704217 520353 810464 704217 -264059 270856 1000000 838639 810464 -264059 0 704217 945100 945100 813177 328488 1000000 270856 -1000000 1000000 520353 233383 328488 -522422 -187632 -187632 373822 810464 653545 838639 -264059 945100 -187632 -22847 810464 373822 373822 0 -187632 -22847 27085...
output:
17
result:
ok 1 number(s): "17"
Test #16:
score: 0
Accepted
time: 0ms
memory: 5948kb
input:
200 181089 -300523 -104331 360450 -108859 1000000 388283 -108859 -118869 -104331 -277725 360450 -104331 727661 1000000 -108859 727661 383704 727661 -628369 727661 -108859 -118869 388283 -83881 -655062 -655062 -199320 1000000 -1000000 -964033 -83881 -964033 -448024 1000000 -104331 569372 800854 38828...
output:
13
result:
ok 1 number(s): "13"
Test #17:
score: 0
Accepted
time: 8ms
memory: 6156kb
input:
200 117900 -838409 411806 34821 -766900 67987 34821 46504 46504 -49913 411806 161685 313760 -49913 596234 156661 67987 -646448 161685 -838409 46504 -236598 -766900 -538744 46504 -49913 599791 -1000000 -538744 34821 -646441 -236598 67987 0 -766900 161685 161685 -305084 34821 0 -49913 46504 -49913 156...
output:
14
result:
ok 1 number(s): "14"
Test #18:
score: 0
Accepted
time: 8ms
memory: 5880kb
input:
200 88724 -233297 630561 -275237 -275237 505621 416897 0 505621 0 -1000000 416897 -888093 -275237 630561 788662 788662 505621 -1000000 416897 -314063 584906 0 -1000000 -888093 1000000 276966 416897 311201 257302 493457 -852985 -233297 493457 563328 788662 -233297 1000000 584906 -1000000 416897 58490...
output:
14
result:
ok 1 number(s): "14"
Test #19:
score: 0
Accepted
time: 8ms
memory: 5876kb
input:
200 739055 -276846 -1000000 -970267 274436 -278344 -276846 690590 -780355 -619119 338671 681144 -970267 537803 338671 -780355 0 885372 -619119 -780355 -711246 235223 274436 445389 460711 460711 -276846 -1000000 690590 400277 681144 351497 -278344 885372 0 -1000000 -711246 -438285 537803 1000000 6905...
output:
15
result:
ok 1 number(s): "15"
Test #20:
score: 0
Accepted
time: 8ms
memory: 5904kb
input:
200 -942994 884626 1000000 -491267 884626 -26900 -362264 916094 -705196 -503120 -730425 -705196 -362264 -503120 763328 -26900 12314 -362264 -26900 -281451 1000000 -26900 -503120 916094 -501391 -501391 -705196 -491267 763328 -841371 636579 -730425 636579 -501391 -730425 -26900 -503120 -841371 -705196...
output:
16
result:
ok 1 number(s): "16"
Test #21:
score: 0
Accepted
time: 7ms
memory: 5828kb
input:
200 863782 -909322 180110 0 -354261 -98424 -539584 509521 -43919 -654935 -43919 -98424 -909322 -795454 -1000000 -5749 474004 932634 -783914 667659 474004 -43919 289728 -1000000 -795454 -43919 -654935 -354261 -179344 -539584 -886774 -43919 289728 1000000 1000000 509521 -179344 932634 180110 -5749 490...
output:
12
result:
ok 1 number(s): "12"
Test #22:
score: 0
Accepted
time: 8ms
memory: 5972kb
input:
200 -86945 4973 274752 -348485 0 -661269 192390 -604418 -604418 0 366658 -618002 366658 200590 113645 1000000 4973 -491231 200590 -933401 -491231 -1000000 0 113645 -357368 192390 -348485 -348485 192390 642587 -462653 -110388 366658 -618002 642587 -491231 -618002 -462653 113645 366658 642587 779540 6...
output:
15
result:
ok 1 number(s): "15"
Test #23:
score: 0
Accepted
time: 8ms
memory: 5940kb
input:
200 -96625 67966 96625 -464136 961712 1000000 1000000 -269712 -1000000 79999 784610 604674 -199318 784610 1000000 96625 -199318 961712 -259853 20672 -1000000 -640882 -640882 -259853 -1000000 604674 604674 604674 -479599 -1000000 -259853 79999 784610 961712 -199318 -199318 -977257 -328717 79999 78461...
output:
13
result:
ok 1 number(s): "13"
Test #24:
score: 0
Accepted
time: 8ms
memory: 6100kb
input:
200 -672541 875140 -239147 0 875140 -126371 546170 -420922 -239147 -126371 -126371 -530108 -1000000 39354 -534942 -926598 -239147 -999662 542231 542231 -126371 546170 70909 -926598 -983208 -409757 -251037 -267623 -534942 -506813 -126371 875140 -267623 -251037 546170 112393 1000000 503549 590746 -239...
output:
16
result:
ok 1 number(s): "16"
Test #25:
score: 0
Accepted
time: 8ms
memory: 6960kb
input:
200 290556 -562226 -470944 -476890 -855535 896680 625399 -375294 546758 -1000000 86661 -500265 928824 906314 -212125 789141 -384224 150468 -728038 180898 86661 182356 371493 906314 999068 557976 727667 371493 208850 -988123 825950 -103281 -287540 719469 -853452 86661 -342794 -500265 -728038 -721633 ...
output:
5
result:
ok 1 number(s): "5"
Test #26:
score: 0
Accepted
time: 8ms
memory: 6684kb
input:
200 179682 929614 -21247 -265968 -21247 -287974 928826 -868203 -563505 514758 877402 173245 -619036 454699 -766433 -592913 948190 629961 68382 948190 636639 -942217 636639 -267329 566108 -623113 -54339 -942217 208640 555793 -804559 795354 -545404 572841 173245 -54339 986929 409171 173245 636639 -685...
output:
7
result:
ok 1 number(s): "7"
Test #27:
score: 0
Accepted
time: 4ms
memory: 6764kb
input:
200 -991752 954660 -596546 -525947 1000000 -679108 -542218 365468 -480731 544554 986182 144161 634196 -590564 -506613 986182 -162018 -368859 21502 189307 789950 835550 -299875 176110 -746851 -549131 635606 -565037 -679108 736710 -182064 -395657 9764 185337 -368859 203349 789950 923902 -485907 -48073...
output:
7
result:
ok 1 number(s): "7"
Test #28:
score: 0
Accepted
time: 8ms
memory: 6672kb
input:
200 569638 -548355 -691936 -578229 621700 -1000000 -628566 -401673 678066 -255352 968872 -77499 905238 -703331 -104566 -300189 -520809 -722912 -879064 -81938 -284893 609667 678066 -578229 -691936 957065 -643485 755266 155923 -81938 740312 -306969 286750 -77499 968872 -639853 -27086 -892181 -809911 1...
output:
6
result:
ok 1 number(s): "6"
Test #29:
score: 0
Accepted
time: 8ms
memory: 6636kb
input:
200 0 910111 -582315 351686 -304954 -981006 -913772 -531700 -665941 -856809 -82453 -16749 -981006 -176952 431945 974583 -896968 -601100 -631689 629948 -459202 974583 381043 -653184 789031 -152004 494958 269840 -214049 -759445 616294 677636 -531700 -222405 -833624 147927 -92940 -135836 865538 -575424...
output:
9
result:
ok 1 number(s): "9"
Test #30:
score: -100
Time Limit Exceeded
input:
1000000 890430 -890430 -1000000 -890430 1000000 0 0 148415 148415 0 1000000 1000000 -890430 658440 658440 658440 0 148415 -1000000 0 0 -890430 842292 842292 148415 -501797 148415 -501797 -501797 842292 658440 1000000 -501797 -1000000 -501797 842292 -501797 658440 842292 658440 1000000 148415 -100000...