QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107529#5459. Goose, goose, DUCK?ycccc319#WA 8ms34504kbC++171.7kb2023-05-21 19:59:012023-05-21 19:59:05

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:59:05]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:34504kb
  • [2023-05-21 19:59:01]
  • 提交

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;
    if(k>n){
        cout<<(n+1)*n/2;
        return 0;
    }
    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);
//    cout << minn << " " << maxn << " " << ans << endl;
    for (int i = 1; i < n; i++) {
        if (zz[num[i]] < wz[num[i]].size()) {//update minn
            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()) {//update maxn
            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);
        else break;
    }
//    cout << ans << endl;
    cout << (n + 1) * n / 2 - ans << "\n";
    return 0;
}

詳細信息

Test #1:

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

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 1ms
memory: 26840kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 8ms
memory: 34504kb

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:

1680

result:

wrong answer 1st numbers differ - expected: '4309', found: '1680'