제출 #1214270

#제출 시각아이디문제언어결과실행 시간메모리
1214270lopkusLottery (CEOI18_lot)C++20
25 / 100
62 ms131072 KiB
#include <bits/stdc++.h>

signed main() {
  int n, l;
  std::cin >> n >> l;
  std::vector<int> a(n + 1);
  for(int i = 1; i <= n; i++) {
    std::cin >> a[i];
  }
  std::vector<std::vector<int>> pref(n + 2, std::vector<int>(n + 1));
  for(int j = 1; j <= n; j++) {
    for(int i = n; i >= 1; i--) {
      pref[i][j] = pref[i + 1][j];
      if(i + j <= n) {
        pref[i][j] += (a[i] != a[i + j]);
      }
    }
  }
  int q;
  std::cin >> q;
  std::vector<int> k(q + 1);
  for(int i = 1; i <= q; i++) {
    std::cin >> k[i];
  }
  std::vector<int> now(n + 1);
  for(int i = 1; i + l - 1 <= n; i++) {
    now[i] = 0;
  }
  std::vector<std::vector<int>> ans(q + 1);
  std::vector<int> query[l + 1];
  for(int i = 1; i <= q; i++) {
    query[k[i]].push_back(i);
  }
  std::vector<std::vector<std::pair<int, int>>> del(l + 1);
  for(int i = 1; i + l - 1 <= n; i++) {
    for(int j = i + 1; j + l - 1 <= n; j++) {
      int s = j - i;
      del[pref[i][s] - pref[i + l][s]].push_back({i, j});
    }
  }
  for(int i = 0; i <= l; i++) {
    for(auto [u, v] : del[i]) {
      now[u]++;
      now[v]++;
    }
    for(auto u : query[i]) {
      for(int j = 1; j + l - 1 <= n; j++) {
        ans[u].push_back(now[j]);
      }
    }
  }
  for(int i = 1; i <= q; i++) {
    for(auto u : ans[i]) {
      std::cout << u << " ";
    }
    std::cout << "\n";
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...