QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#712894 | #9584. 顾影自怜 | fsy_juruo | WA | 100ms | 31128kb | C++17 | 1.4kb | 2024-11-05 17:24:54 | 2024-11-05 17:24:55 |
Judging History
answer
#include <bits/stdc++.h>
using LL = long long;
const int maxN = 1e6 + 10;
int T, n, k;
int a[maxN], max[maxN][21];
std::vector<int> e[maxN];
std::set<int> allowed, banned, neg;
int main() {
std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
std::cin >> T;
while(T--) {
std::cin >> n >> k;
if(k == 1) {
LL ans = 1ll * n * (n + 1) / 2;
std::cout << ans << "\n";
continue;
}
for(int i = 1; i <= n; i++) {
std::cin >> a[i];
e[a[i]].emplace_back(i);
banned.insert(i);
neg.insert(-i);
}
LL ans = 0;
banned.insert(n + 1);
neg.insert(0);
for(int i = 1; i <= n; i++) {
for(auto u : e[i]) {
banned.erase(u);
allowed.insert(u);
neg.erase(-u);
}
if(e[i].size() < k) continue;
for(int j = 0; j <= e[i].size() - k; j++) {
int require = e[i][j + k - 1];
int pos = *banned.lower_bound(e[i][j]);
if(require <= pos - 1) {
int lpos = -(*neg.lower_bound(-e[i][j]));
lpos = std::max(lpos, (j == 0 ? 0 : e[i][j - 1]));
ans += 1ll * (e[i][j] - lpos) * (pos - require);
// std::cout << pos << " " << lpos << " " << i << " " << e[i][j] << " " << require << "\n";
}
}
}
std::cout << ans << "\n";
for(int i = 1; i <= n; i++) {
e[a[i]].clear();
}
allowed.clear();
banned.clear();
neg.clear();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 31128kb
input:
2 5 2 1 3 3 2 2 4 3 1 4 2 1
output:
7 0
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 3ms
memory: 28344kb
input:
1 1000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
500000500000
result:
ok single line: '500000500000'
Test #3:
score: -100
Wrong Answer
time: 100ms
memory: 30876kb
input:
158921 1 1 1 2 1 1 1 2 2 1 1 2 1 1 2 2 2 1 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 2 3 1 1 1 1 3 2 1 1 1 3 3 1 1 1 3 1 1 1 2 3 2 1 1 2 3 3 1 1 2 3 1 1 1 3 3 2 1 1 3 3 3 1 1 3 3 1 1 2 1 3 2 1 2 1 3 3 1 2 1 3 1 1 2 2 3 2 1 2 2 3 3 1 2 2 3 1 1 2 3 3 2 1 2 3 3 3 1 2 3 3 1 1 3 1 3 2 1 3 1 3 3 1 3 1 3 1 1 3 2 3 2...
output:
1 0 1 1 3 0 3 0 0 3 3 1 0 1 0 1 0 1 0 1 0 0 6 0 1 0 3 0 6 0 1 3 0 0 6 0 2 0 6 0 0 0 6 0 0 0 6 0 0 0 6 0 2 0 6 3 0 3 0 3 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 2 0 0 0 0 1 1 0 6 6 0 0 0 0 0 0 0 0 2 0 0 2 0 2 3 2 0 0 0 0 0 0 0 1 0 1 1 6 3 1 10 1 0 3 1 0 1 0 1 0 1 0 0 6 1 0 0 1 1 0 0 0 0 0 1...
result:
wrong answer 2nd lines differ - expected: '3', found: '0'