Submission #438695

# Submission time Handle Problem Language Result Execution time Memory
438695 2021-06-28T13:30:15 Z peijar Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
824 ms 33092 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int INF = 2e9;

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

  int nbPersonnes, nbRequetes;
  cin >> nbPersonnes >> nbRequetes;

  vector<int> lenteurs(nbPersonnes + 1);
  for (int iPersonne = 1; iPersonne <= nbPersonnes; ++iPersonne)
    cin >> lenteurs[iPersonne];

  vector<int> frequency(nbPersonnes + 1), delta(nbPersonnes + 1);
  frequency[0] = 1, delta[0] = 1;

  for (int iPersonne = 1; iPersonne <= nbPersonnes; ++iPersonne) {
    int nbFois =
        (lenteurs[iPersonne] + delta[iPersonne - 1] - 1) / delta[iPersonne - 1];
    frequency[iPersonne] = nbFois * frequency[iPersonne - 1];
    if (frequency[iPersonne] > INF) {
      frequency[iPersonne] = delta[iPersonne] = INF;

      continue;
    }
    delta[iPersonne] = delta[iPersonne - 1] * nbFois;
  }

  auto calcPos = [&](int iPer, int curT) {
    int nbFois = curT / frequency[iPer];
    return -iPer + nbFois * delta[iPer];
  };

  auto calcLess = [&](int bound, int curT) -> int {
    if (calcPos(nbPersonnes, curT) >= bound)
      return 0;
    int lo = 0, up = nbPersonnes;
    while (lo < up) {
      int mid = (lo + up) / 2;
      if (calcPos(mid, curT) < bound)
        up = mid;
      else
        lo = mid + 1;
    };
    return nbPersonnes - lo + 1;
  };

  for (int iRequete = 0; iRequete < nbRequetes; ++iRequete) {
    int temps, deb, fin;
    cin >> temps >> deb >> fin;
    /*int ret = 0;
    for (int iPer = 0; iPer <= nbPersonnes; ++iPer) {
      int pos = calcPos(iPer, temps);
      if (pos >= deb and pos <= fin)
        ret++;
    }
    cout << ret << '\n';*/
    cout << calcLess(fin + 1, temps) - calcLess(deb, temps) << '\n';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 759 ms 30408 KB Output is correct
2 Correct 812 ms 30468 KB Output is correct
3 Correct 815 ms 30516 KB Output is correct
4 Correct 824 ms 30448 KB Output is correct
5 Correct 753 ms 30524 KB Output is correct
6 Correct 785 ms 30412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 759 ms 30408 KB Output is correct
2 Correct 812 ms 30468 KB Output is correct
3 Correct 815 ms 30516 KB Output is correct
4 Correct 824 ms 30448 KB Output is correct
5 Correct 753 ms 30524 KB Output is correct
6 Correct 785 ms 30412 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 409 ms 29084 KB Output is correct
14 Correct 418 ms 29636 KB Output is correct
15 Correct 407 ms 28176 KB Output is correct
16 Correct 403 ms 28712 KB Output is correct
17 Correct 526 ms 32964 KB Output is correct
18 Correct 543 ms 33028 KB Output is correct
19 Correct 546 ms 33000 KB Output is correct
20 Correct 570 ms 33092 KB Output is correct
21 Correct 563 ms 32944 KB Output is correct
22 Correct 519 ms 33004 KB Output is correct
23 Correct 517 ms 32908 KB Output is correct
24 Correct 526 ms 33028 KB Output is correct
25 Correct 756 ms 30524 KB Output is correct
26 Correct 803 ms 30560 KB Output is correct
27 Correct 624 ms 32520 KB Output is correct
28 Correct 574 ms 32900 KB Output is correct
29 Correct 604 ms 32452 KB Output is correct
30 Correct 668 ms 32568 KB Output is correct
31 Correct 585 ms 32956 KB Output is correct
32 Correct 608 ms 29096 KB Output is correct
33 Correct 1 ms 204 KB Output is correct