QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#516667 | #5459. Goose, goose, DUCK? | no_RED_no_DEAD | WA | 1ms | 5664kb | C++20 | 1.2kb | 2024-08-12 20:12:39 | 2024-08-12 20:12:40 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll N = 1e6 + 1;
const ll M = 1e9 + 7;
ll n, k;
ll a[N], cnt[N];
map<ll, ll> m;
ll cal(ll k) {
m.clear(); ll j = 0, res = 0; m[0] = n;
for (int i = 1; i <= n; i ++) cnt[i] = 0;
for (int i = 1; i <= n; i ++) {
while (m.rbegin()->first < k && j <= n) {
m[cnt[a[j + 1]]] --; if (m[cnt[a[j + 1]]] == 0) m.erase(cnt[a[j + 1]]);
cnt[a[j + 1]] ++;
m[cnt[a[j + 1]]] ++;
j ++;
// cout << "Spec: " << j << ' ' << m.rbegin()->first << endl;
}
// cout << "Debug: " << i << ' ' << j << endl;
// for (auto [x, y]: m) cout << x << ' ' << y << endl;
if (j - i > 0) res += j - i;
m[cnt[a[i]]] --; if (m[cnt[a[i]]] == 0) m.erase(cnt[a[i]]);
cnt[a[i]] --;
m[cnt[a[i]]] ++;
}
return res;
}
void doTest(ll testID) {
cin >> n >> k;
for (int i = 1; i <= n; i ++) cin >> a[i];
// cout << cal(k) << endl;
cout << cal(k) - cal(k - 1);
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int test = 1;
// cin >> test;
for (int _ = 1; _ <= test; _ ++) doTest(test);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5664kb
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: 5612kb
input:
6 1 1 2 3 4 5 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5612kb
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:
204
result:
wrong answer 1st numbers differ - expected: '4309', found: '204'