QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107526#5459. Goose, goose, DUCK?ycccc319#RE 4ms26864kbC++171.5kb2023-05-21 19:46:592023-05-21 19:47:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-21 19:47:02]
  • 评测
  • 测评结果:RE
  • 用时:4ms
  • 内存:26864kb
  • [2023-05-21 19:46:59]
  • 提交

answer

#include <bits/extc++.h>

#define int long long
using namespace std;
int n, k;
int num[1000010];
vector<int> wz[1000010];
int zz[1000010];
int task = 0;
priority_queue<int, vector<int>, greater<int> > q;
unordered_map<int, bool> up;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> num[i];
        task = max(task, num[i]);
        wz[num[i]].push_back(i);
    }
    int minn = 0x3f3f3f3f, maxn = 0;
    int ans = 0;
    for (int i = 1; i <= task; i++) {
        if (wz[i].size() <= k) {
            minn = min(minn, wz[i][k - 1]);
            maxn = max(maxn, wz[i][k - 1]);
            q.push(wz[i][k - 1]);
//            cout << wz[i][k - 1] << endl;
        }
        zz[i] = k - 1;
    }

    ans += (maxn - minn + 1);
    for (int i = 1; i < n; i++) {
        if (zz[num[i]] < wz[num[i]].size()) {
            up[wz[num[i]][zz[num[i]]]] = 1;
            bool need_update = 0;
            if (!q.empty() && q.top() == minn)need_update = 1;
            while (!q.empty() && up[q.top()] == 1)q.pop();
            if (!q.empty() && need_update)minn = q.top();
        }
        zz[num[i]]++;
        if (zz[num[i]] < wz[num[i]].size()) {
            maxn = max(maxn, wz[num[i]][zz[num[i]]]);
            q.push(wz[num[i]][zz[num[i]]]);
//            cout << i << " " << wz[num[i]][zz[num[i]]] << endl;
        }
        if (!q.empty())ans += (maxn - minn + 1);
    }
    cout << (n + 1) * n / 2 - ans << "\n";
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 26864kb

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

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

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Runtime Error

input:

100 10
142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...

output:


result: