답안 #680280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680280 2023-01-10T12:49:07 Z peijar Lottery (CEOI18_lot) C++17
100 / 100
1199 ms 12276 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
  out << "[";
  for (int i = 0; i < (int)vec.size(); ++i) {
    out << vec[i];
    if (i + 1 < (int)vec.size())
      out << ", ";
  }
  return out << "]";
}
} // namespace std

void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
  cout << ' ' << H;
  dbg_out(T...);
}

#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int nbElem, len;
  cin >> nbElem >> len;
  vector<int> arr(nbElem);
  for (int &x : arr)
    cin >> x;

  int nbRequetes;
  cin >> nbRequetes;

  vector<vector<int>> sol(nbRequetes, vector<int>(nbElem - len + 1));

  vector<pair<int, int>> queries(nbRequetes);
  for (int i = 0; i < nbRequetes; ++i) {
    int nbDiffs;
    cin >> nbDiffs;
    int nbEgaux = len - nbDiffs;
    queries[i] = pair(nbEgaux, i);
  }
  sort(queries.begin(), queries.end());
  for (int delta = 1; delta < nbElem; ++delta) {
    vector<int> prefSum(nbElem - delta + 1);
    for (int i = 0; i + delta < nbElem; ++i)
      prefSum[i + 1] = prefSum[i] + (arr[i] == arr[i + delta]);
    for (int i = 0; i + delta < nbElem; ++i) {
      int j = i + delta;
      if (j + len > nbElem)
        break;
      int nbEgaux = prefSum[i + len] - prefSum[i];
      sol[0][i]++;
      sol[0][j]++;
      int end = upper_bound(queries.begin(), queries.end(),
                            pair(nbEgaux, (int)1e18)) -
                queries.begin();
      if (end < nbRequetes) {
        sol[end][i]--;
        sol[end][j]--;
      }
    }
  }
  for (int iRequete = 1; iRequete < nbRequetes; ++iRequete)
    for (int i = 0; i + len <= nbElem; ++i)
      sol[iRequete][i] += sol[iRequete - 1][i];
  vector<int> pos(nbRequetes);
  for (int i = 0; i < nbRequetes; ++i)
    pos[queries[i].second] = i;

  for (int i = 0; i < nbRequetes; ++i) {
    for (int x : sol[pos[i]])
      cout << x << ' ';
    cout << endl;
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 29 ms 448 KB Output is correct
14 Correct 15 ms 592 KB Output is correct
15 Correct 10 ms 488 KB Output is correct
16 Correct 18 ms 716 KB Output is correct
17 Correct 15 ms 724 KB Output is correct
18 Correct 15 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 636 KB Output is correct
2 Correct 405 ms 716 KB Output is correct
3 Correct 394 ms 596 KB Output is correct
4 Correct 385 ms 708 KB Output is correct
5 Correct 142 ms 636 KB Output is correct
6 Correct 343 ms 752 KB Output is correct
7 Correct 109 ms 636 KB Output is correct
8 Correct 172 ms 660 KB Output is correct
9 Correct 361 ms 724 KB Output is correct
10 Correct 383 ms 724 KB Output is correct
11 Correct 19 ms 332 KB Output is correct
12 Correct 207 ms 636 KB Output is correct
13 Correct 170 ms 664 KB Output is correct
14 Correct 177 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 636 KB Output is correct
2 Correct 405 ms 716 KB Output is correct
3 Correct 394 ms 596 KB Output is correct
4 Correct 385 ms 708 KB Output is correct
5 Correct 142 ms 636 KB Output is correct
6 Correct 343 ms 752 KB Output is correct
7 Correct 109 ms 636 KB Output is correct
8 Correct 172 ms 660 KB Output is correct
9 Correct 361 ms 724 KB Output is correct
10 Correct 383 ms 724 KB Output is correct
11 Correct 19 ms 332 KB Output is correct
12 Correct 207 ms 636 KB Output is correct
13 Correct 170 ms 664 KB Output is correct
14 Correct 177 ms 652 KB Output is correct
15 Correct 321 ms 640 KB Output is correct
16 Correct 340 ms 700 KB Output is correct
17 Correct 388 ms 724 KB Output is correct
18 Correct 378 ms 724 KB Output is correct
19 Correct 381 ms 724 KB Output is correct
20 Correct 357 ms 724 KB Output is correct
21 Correct 386 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 29 ms 448 KB Output is correct
14 Correct 15 ms 592 KB Output is correct
15 Correct 10 ms 488 KB Output is correct
16 Correct 18 ms 716 KB Output is correct
17 Correct 15 ms 724 KB Output is correct
18 Correct 15 ms 680 KB Output is correct
19 Correct 455 ms 636 KB Output is correct
20 Correct 405 ms 716 KB Output is correct
21 Correct 394 ms 596 KB Output is correct
22 Correct 385 ms 708 KB Output is correct
23 Correct 142 ms 636 KB Output is correct
24 Correct 343 ms 752 KB Output is correct
25 Correct 109 ms 636 KB Output is correct
26 Correct 172 ms 660 KB Output is correct
27 Correct 361 ms 724 KB Output is correct
28 Correct 383 ms 724 KB Output is correct
29 Correct 19 ms 332 KB Output is correct
30 Correct 207 ms 636 KB Output is correct
31 Correct 170 ms 664 KB Output is correct
32 Correct 177 ms 652 KB Output is correct
33 Correct 321 ms 640 KB Output is correct
34 Correct 340 ms 700 KB Output is correct
35 Correct 388 ms 724 KB Output is correct
36 Correct 378 ms 724 KB Output is correct
37 Correct 381 ms 724 KB Output is correct
38 Correct 357 ms 724 KB Output is correct
39 Correct 386 ms 844 KB Output is correct
40 Correct 842 ms 2880 KB Output is correct
41 Correct 66 ms 736 KB Output is correct
42 Correct 445 ms 2840 KB Output is correct
43 Correct 415 ms 2512 KB Output is correct
44 Correct 385 ms 2644 KB Output is correct
45 Correct 1199 ms 12152 KB Output is correct
46 Correct 62 ms 1644 KB Output is correct
47 Correct 851 ms 12276 KB Output is correct
48 Correct 559 ms 10216 KB Output is correct
49 Correct 559 ms 10780 KB Output is correct