QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#516692 | #5459. Goose, goose, DUCK? | no_RED_no_DEAD | WA | 1ms | 5756kb | C++20 | 1.3kb | 2024-08-12 20:37:47 | 2024-08-12 20:37:47 |
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 + 1 <= 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;
if (m.rbegin()->first < k) res ++;
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 << n * (n + 1) / 2 - cal(k + 1) + cal(k);
}
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: 5756kb
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: 5688kb
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: 5636kb
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:
4836
result:
wrong answer 1st numbers differ - expected: '4309', found: '4836'