QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684758#6433. Klee in Solitary Confinementcatch-up-from-behind#TL 3ms28832kbC++171.3kb2024-10-28 15:38:232024-10-28 15:38:23

Judging History

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

  • [2024-10-28 15:38:23]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:28832kb
  • [2024-10-28 15:38:23]
  • 提交

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;
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;
}


详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 28268kb

input:

5 2
2 2 4 4 4

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

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: 28832kb

input:

7 1
2 3 2 3 2 3 3

output:

5

result:

ok 1 number(s): "5"

Test #4:

score: -100
Time Limit Exceeded

input:

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

output:


result: