답안 #128124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128124 2019-07-10T12:46:37 Z RockyB Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
847 ms 30788 KB
#include <bits/stdc++.h>
 
#define int ll
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
 
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
 
#define rep(a, b, c) for (int a = (b); (a) <= (c); ++a)
#define per(a, b, c) for (int a = (b); (a) >= (c); --a) 
 
#define nl '\n'
#define ioi exit(0);
 
using namespace std;
 
typedef long long ll;
 
const int MAX_N = (int)5e5 + 7;
 
int n, q;
int d[MAX_N], l[MAX_N], r[MAX_N], t[MAX_N], ans[MAX_N];
 
map <int, vector <int> > off;
 
int nxt[MAX_N], lst[MAX_N];
void prep() {
  int last = 1;
  rep(i, 1, n) {
    int df = (d[i] + last - 1) / last;
    lst[i] = df * last;
    last *= df;
  }
  per(i, n, 1) {
    if (lst[i] != lst[i + 1] || i == n) nxt[i] = i + 1;
    else nxt[i] = nxt[i + 1];
  }
}

pair < pair <int, int>, ll> a[MAX_N];
void solve(int T, const vector <int> &qr) {
  int add = T;
  int sz = 0;
  int last = 1;
  for (int i = 1, j = 0; i <= n; j = i + 1, i = nxt[i]) {
    int df = (d[i] + last - 1) / last;
 
    if (!sz) a[sz++] = {{0, i - 1}, i - 1};
    else a[sz++] = {{j, i - 1}, {i - j}};
    a[sz++] = {{i, i}, 1 + last * (add % df)};
    last *= df;
    add /= df;
    if (!add || nxt[i] > n) {
      if (i < n) a[sz++] = {{i + 1, n}, {n - i}};
      break;
    }
  }
  for (auto it : qr) {
    int L = -1, R = -2;
    if (T >= l[it]) { // it's for right
      int ost = T - l[it];
      if (sz) {
        R = min(ost, a[0].s);
      }
    }
    int sum = 0;
    rep(i, 0, sz - 1) {
      sum += a[i].s;
      int val = T - sum;
      if (val >= l[it]) {
        R = a[i].f.s;
        
        int ost = val - l[it];
        if (i & 1 && i + 1 < sz) {
          R += min(ost, a[i + 1].s);
        }
      }
      if (val <= r[it] && L == -1) {
        L = a[i].f.s;
        if (i % 2 == 0) {
          L -= max(0ll, min(r[it] - val, a[i].s - 1));
        }
      }
    }
    if (L != -1 && L <= R) ans[it] += R - L + 1;
  } 
}
int32_t main() {
  #ifdef IOI
    freopen ("in.txt", "r", stdin);
    freopen ("C.out", "w", stdout);
  #endif
  ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  d[0] = 1;
  rep(i, 1, n) {
    cin >> d[i];
  }
  prep();
  rep(i, 1, q) {
    cin >> t[i] >> l[i] >> r[i];
    solve(t[i], {i});
  }
  rep(i, 1, q) {
    cout << ans[i] << nl;
  }
 
  ioi
}
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 30712 KB Output is correct
2 Correct 361 ms 30736 KB Output is correct
3 Correct 360 ms 30780 KB Output is correct
4 Correct 361 ms 30696 KB Output is correct
5 Correct 383 ms 30788 KB Output is correct
6 Correct 373 ms 30688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 30712 KB Output is correct
2 Correct 361 ms 30736 KB Output is correct
3 Correct 360 ms 30780 KB Output is correct
4 Correct 361 ms 30696 KB Output is correct
5 Correct 383 ms 30788 KB Output is correct
6 Correct 373 ms 30688 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 387 ms 28780 KB Output is correct
14 Correct 400 ms 28768 KB Output is correct
15 Correct 358 ms 28764 KB Output is correct
16 Correct 381 ms 28708 KB Output is correct
17 Correct 725 ms 30152 KB Output is correct
18 Correct 705 ms 30252 KB Output is correct
19 Correct 745 ms 30156 KB Output is correct
20 Correct 724 ms 30200 KB Output is correct
21 Correct 701 ms 30136 KB Output is correct
22 Correct 710 ms 30088 KB Output is correct
23 Correct 731 ms 30212 KB Output is correct
24 Correct 710 ms 30144 KB Output is correct
25 Correct 385 ms 30724 KB Output is correct
26 Correct 418 ms 30712 KB Output is correct
27 Correct 847 ms 30660 KB Output is correct
28 Correct 807 ms 30496 KB Output is correct
29 Correct 796 ms 30596 KB Output is correct
30 Correct 787 ms 30768 KB Output is correct
31 Correct 778 ms 30444 KB Output is correct
32 Correct 377 ms 30172 KB Output is correct
33 Correct 2 ms 376 KB Output is correct