QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#697101#6433. Klee in Solitary Confinementfsy_juruo#WA 11ms75932kbC++171.3kb2024-11-01 10:28:542024-11-01 10:28:54

Judging History

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

  • [2024-11-01 10:28:54]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:75932kb
  • [2024-11-01 10:28:54]
  • 提交

answer

#include <bits/stdc++.h>
const int maxn = 1e6 + 10;
const int py = 1e6;
using namespace std;
vector<int> vec[maxn * 3];
int a[maxn], n, k;
pair<int, int> f[maxn];
int cnt;
int pre[maxn], s[maxn];
int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        a[i] = a[i] + py;
        vec[a[i]].push_back(i);
    }
    int ans = 0;
    for (int now = 1e6; now <= 1e6+5; now++)
    { // i and i-k
        
        int prev = now - k;
        ans = max(ans, (int)vec[now].size());
        if (vec[now].empty())
            continue;
        if (prev < 0 || prev > 2e6 || vec[prev].empty())
            continue;
        cnt = 0;
        for (auto v : vec[now])
            f[++cnt] = make_pair(v, 1);
        for (auto v : vec[prev])
            f[++cnt] = make_pair(v, 0);
        sort(f + 1, f + 1 + cnt);
        int ret = 0;
        for (int i = 1; i <= cnt; i++)
        {
            a[i] = f[i].second;
            pre[i] = pre[i - 1] + a[i];
        }
        for (int i = 1; i <= cnt; i++)
        {
            ans = max(ans, pre[cnt] + i - 2 * pre[i] + ret);
            ret = max(ret, 2 * pre[i] - i);
        }
        //cout<<now<<' '<<ans<<endl;
    }
    cout<<ans<<endl;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 74356kb

input:

5 2
2 2 4 4 4

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 8ms
memory: 75420kb

input:

7 1
3 2 3 2 2 2 3

output:

6

result:

ok 1 number(s): "6"

Test #3:

score: 0
Accepted
time: 11ms
memory: 74584kb

input:

7 1
2 3 2 3 2 3 3

output:

5

result:

ok 1 number(s): "5"

Test #4:

score: 0
Accepted
time: 4ms
memory: 75932kb

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

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:

29

result:

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