QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#107530 | #5459. Goose, goose, DUCK? | ycccc319# | WA | 7ms | 34564kb | C++17 | 1.7kb | 2023-05-21 20:00:43 | 2023-05-21 20:00:44 |
Judging History
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;
}
if(maxn>0)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: 7ms
memory: 26904kb
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: 26812kb
input:
6 1 1 2 3 4 5 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 34564kb
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'