QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#497668#6433. Klee in Solitary ConfinementUmokWA 16ms131760kbC++202.2kb2024-07-29 15:42:452024-07-29 15:42:45

Judging History

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

  • [2024-07-29 15:42:45]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:131760kb
  • [2024-07-29 15:42:45]
  • 提交

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]);
            while (r != l && idxs != v[ar[i] + N].end() && (*r) < (*idxs))
            {
                ans = max(ans, pre[i] + back[*l] + back[*idxs]);
                idxs--;
                if (idxs != v[ar[i] + N].begin() && *idxs <= i)
                    while (l != r && *r >= *idxs)
                        r--;
            }
        }
        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]);
            while (r != l && idxs != v[ar[i] + N].end() && (*r) < (*idxs))
            {
                ans = max(ans, pre[i] + back[*l] + back[*idxs]);
                idxs--;
                if (idxs != v[ar[i] + N].begin() && *idxs <= i)
                    while (l != r && *r >= *idxs)
                        r--;
            }
        }
    }

    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: 100
Accepted
time: 12ms
memory: 131756kb

input:

5 2
2 2 4 4 4

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 12ms
memory: 131696kb

input:

7 1
3 2 3 2 2 2 3

output:

6

result:

ok 1 number(s): "6"

Test #3:

score: 0
Accepted
time: 16ms
memory: 130208kb

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

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: 7ms
memory: 128472kb

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'