QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#684768#6433. Klee in Solitary Confinementcatch-up-from-behind#WA 6ms28692kbC++171.3kb2024-10-28 15:44:292024-10-28 15:44:29

Judging History

你现在查看的是最新测评结果

  • [2024-10-28 15:44:29]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:28692kb
  • [2024-10-28 15:44:29]
  • 提交

answer

// sis puella oier
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
ll read(){
    ll xx = 0, f = 1; char ch = getchar();
    for (;!isdigit(ch); ch = getchar())f = (ch == '-' ? -1 : 1);
    for (; isdigit(ch); ch = getchar())xx = (xx << 3) + (xx << 1) + ch - '0';
    return xx * f;
}
const int N = 1000100;
int n, k;
unordered_map <int, int> mp;
vector <int> ve[N];
int cnt = 0, a[N];
int get(int val, int l, int r){
    if (mp[val] == 0)return 0;
    if (l > r)return 0;
    int id = mp[val];
    return upper_bound(ve[id].begin(), ve[id].end(), r) - lower_bound(ve[id].begin(), ve[id].end(), l);
}
int ans = 0;
signed main(){
    n = read(), k = read();
    for (int i = 1; i <= n; ++i){
        a[i] = read();
        if (mp[a[i]] == 0)mp[a[i]] = ++cnt;
        ve[mp[a[i]]].push_back(i);
    }
    for (auto it : mp){
        int val = it.first - k, id = it.second;
        int mx = 0, lst = 0, len = ve[id].size();
        for (int v : ve[id]){
            --mx; mx = max(mx, get(val, lst + 1, v - 1));
            ans = max(ans, mx + len);
            lst = v;
        }
        --mx; mx = max(mx, get(val, lst + 1, n));
        ans = max(ans, mx + len);
    }
    printf("%d\n", ans);
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 27664kb

input:

5 2
2 2 4 4 4

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 0ms
memory: 28632kb

input:

7 1
3 2 3 2 2 2 3

output:

6

result:

ok 1 number(s): "6"

Test #3:

score: 0
Accepted
time: 3ms
memory: 28692kb

input:

7 1
2 3 2 3 2 3 3

output:

5

result:

ok 1 number(s): "5"

Test #4:

score: 0
Accepted
time: 3ms
memory: 27252kb

input:

9 -100
-1 -2 1 2 -1 -2 1 -2 1

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: -100
Wrong Answer
time: 5ms
memory: 28612kb

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:

36

result:

wrong answer 1st numbers differ - expected: '37', found: '36'