QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#336658#5459. Goose, goose, DUCK?LainWA 5ms26692kbC++231.1kb2024-02-24 18:47:152024-02-24 18:47:15

Judging History

你现在查看的是最新测评结果

  • [2024-02-24 18:47:15]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:26692kb
  • [2024-02-24 18:47:15]
  • 提交

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';
}

详细

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'