답안 #44050

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44050 2018-03-29T12:57:20 Z wxh010910 Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
990 ms 11568 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 500005;

LL a[N], b[N];
int n, m;

inline int Solve(int t, int p) {
  int ret = n + 1, l = 0, r = n;
  while (l <= r) {
    int mid = l + r >> 1;
    if (t / b[mid] * a[mid] - mid <= p) {
      ret = mid, r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return ret;
}

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n), Read(m), a[0] = b[0] = 1;
  for (int i = 1; i <= n; ++i) {
    Read(a[i]);
    a[i] = (a[i] + a[i - 1] - 1) / a[i - 1] * a[i - 1];
    b[i] = b[i - 1] * (a[i] / a[i - 1]);
  }
  for (int i = 1, t, l, r; i <= m; ++i) {
    Read(t), Read(l), Read(r);
    printf("%d\n", Solve(t, l - 1) - Solve(t, r));
  }
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}

Compilation message

worst_reporter3.cpp: In function 'int Solve(int, int)':
worst_reporter3.cpp:49:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 946 ms 11312 KB Output is correct
2 Correct 990 ms 11312 KB Output is correct
3 Correct 925 ms 11312 KB Output is correct
4 Correct 856 ms 11324 KB Output is correct
5 Correct 890 ms 11324 KB Output is correct
6 Correct 883 ms 11488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 11488 KB Output is correct
2 Correct 3 ms 11488 KB Output is correct
3 Correct 2 ms 11488 KB Output is correct
4 Correct 2 ms 11488 KB Output is correct
5 Correct 2 ms 11488 KB Output is correct
6 Correct 2 ms 11488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 946 ms 11312 KB Output is correct
2 Correct 990 ms 11312 KB Output is correct
3 Correct 925 ms 11312 KB Output is correct
4 Correct 856 ms 11324 KB Output is correct
5 Correct 890 ms 11324 KB Output is correct
6 Correct 883 ms 11488 KB Output is correct
7 Correct 3 ms 11488 KB Output is correct
8 Correct 3 ms 11488 KB Output is correct
9 Correct 2 ms 11488 KB Output is correct
10 Correct 2 ms 11488 KB Output is correct
11 Correct 2 ms 11488 KB Output is correct
12 Correct 2 ms 11488 KB Output is correct
13 Correct 478 ms 11488 KB Output is correct
14 Correct 485 ms 11488 KB Output is correct
15 Correct 471 ms 11488 KB Output is correct
16 Correct 466 ms 11488 KB Output is correct
17 Correct 662 ms 11488 KB Output is correct
18 Correct 654 ms 11488 KB Output is correct
19 Correct 636 ms 11488 KB Output is correct
20 Correct 652 ms 11488 KB Output is correct
21 Correct 639 ms 11488 KB Output is correct
22 Correct 632 ms 11488 KB Output is correct
23 Correct 627 ms 11488 KB Output is correct
24 Correct 641 ms 11488 KB Output is correct
25 Correct 910 ms 11488 KB Output is correct
26 Correct 891 ms 11564 KB Output is correct
27 Correct 691 ms 11568 KB Output is correct
28 Correct 664 ms 11568 KB Output is correct
29 Correct 656 ms 11568 KB Output is correct
30 Correct 733 ms 11568 KB Output is correct
31 Correct 707 ms 11568 KB Output is correct
32 Correct 724 ms 11568 KB Output is correct
33 Correct 2 ms 11568 KB Output is correct