QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#336658 | #5459. Goose, goose, DUCK? | Lain | WA | 5ms | 26692kb | C++23 | 1.1kb | 2024-02-24 18:47:15 | 2024-02-24 18:47:15 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
const int N = 1e6+7;
int n, k;
cin >> n >> k;
k--;
vector<vi> indices(N);
vi a(n);
vi value_idx(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
value_idx[i] = indices[a[i]].size();
indices[a[i]].push_back(i);
}
int64_t ans = 0;
multiset<int> bad_idxs;
for (int i =0; i < n; i++) {
int j = value_idx[i];
int before = j - k - 1;
if (before >= 0) {
int val = indices[a[i]][before];
bad_idxs.erase(bad_idxs.find(val));
}
int after = j - k;
if (after >= 0) {
int val = indices[a[i]][after];
bad_idxs.insert(val);
}
int lim = -1;
if (bad_idxs.size()) {
lim = *bad_idxs.rbegin();
}
ans += i - lim;
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 26608kb
input:
6 2 1 2 2 1 3 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 5ms
memory: 26660kb
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: 26692kb
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:
1943
result:
wrong answer 1st numbers differ - expected: '4309', found: '1943'