QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#497661 | #6433. Klee in Solitary Confinement | Umok | WA | 14ms | 133916kb | C++20 | 1.8kb | 2024-07-29 15:38:05 | 2024-07-29 15:38:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned long long
#define int long long
#define endl '\n'
const int N = 2e6 + 5;
typedef pair<int, int> PII;
#define MAX LONG_LONG_MAX
int ar[N];
int num[2 * N];
int pre[N], back[N];
void solve()
{
int n, m, ans = 0;
cin >> n >> m;
vector<vector<int>> v(2 * N);
for (int i = 1; i <= n; i++)
{
cin >> ar[i];
v[ar[i] + N].push_back(i);
num[ar[i] + N]++;
pre[i] = num[ar[i] + N];
ans = max(ans, num[ar[i] + N]);
}
memset(num, 0, sizeof num);
for (int i = n; i; i--)
{
num[ar[i] + N]++;
back[i] = num[ar[i] + N];
}
for (int i = 1; i <= n; i++)
{
auto l = upper_bound(v[ar[i] - m + N].begin(), v[ar[i] - m + N].end(), i);
auto r = v[ar[i] - m + N].end();
if (l != r)
{
r--;
auto idxs = upper_bound(v[ar[i] + N].begin(), v[ar[i] + N].end(), *r);
ans = max(ans, pre[i] + back[*l]);
if (r != l && idxs != v[ar[i] + N].end() && (*r) < (*idxs))
ans = max(ans, pre[i] + back[*l] + back[*idxs]);
}
l = upper_bound(v[ar[i] + m + N].begin(), v[ar[i] + m + N].end(), i);
r = v[ar[i] + m + N].end();
if (l != r)
{
r--;
auto idxs = upper_bound(v[ar[i] + N].begin(), v[ar[i] + N].end(), *r);
ans = max(ans, pre[i] + back[*l]);
if (r != l && idxs != v[ar[i] + N].end() && (*r) < (*idxs))
ans = max(ans, pre[i] + back[*l] + back[*idxs]);
}
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 131692kb
input:
5 2 2 2 4 4 4
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 14ms
memory: 133876kb
input:
7 1 3 2 3 2 2 2 3
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 0
Accepted
time: 12ms
memory: 131700kb
input:
7 1 2 3 2 3 2 3 3
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 11ms
memory: 131700kb
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: 12ms
memory: 133916kb
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:
38
result:
wrong answer 1st numbers differ - expected: '37', found: '38'