QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#497656#6433. Klee in Solitary ConfinementUmokWA 13ms115356kbC++201.8kb2024-07-29 15:36:052024-07-29 15:36:06

Judging History

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

  • [2024-07-29 15:36:06]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:115356kb
  • [2024-07-29 15:36:05]
  • 提交

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[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++)
        pre[i] = back[i] = 0;

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 13ms
memory: 115356kb

input:

5 2
2 2 4 4 4

output:

10

result:

wrong answer 1st numbers differ - expected: '5', found: '10'