답안 #779812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779812 2023-07-11T22:39:05 Z tvladm2009 Worst Reporter 3 (JOI18_worst_reporter3) C++17
12 / 100
37 ms 29392 KB
#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
const int N = (int) 5e5 + 7;
int d[N], when[N], jump[N];
int n, q;

struct T {
  int l;
  int r;
  int id;
};

vector<T> questions[N];
int sol[N];

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

  // freopen("input", "r", stdin);

  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
  }
  int mxt = 0;
  for (int i = 1; i <= q; i++) {
    int t, l, r;
    cin >> t >> l >> r;
    mxt = max(mxt, t);
    questions[t].push_back({l, r, i});
  }
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    a[i] = -i;
  }
  when[1] = d[1];
  jump[1] = d[1];
  for (int i = 2; i <= n; i++) {
    int from = -i + d[i] + 1 + (i - 1);
    assert(jump[i - 1] != 0);
    int moment = (from - 1) / jump[i - 1] + 1;
    int t = when[i - 1] * moment;
    when[i] = t;
    jump[i] = a[i - 1] + jump[i - 1] * (when[i] / when[i - 1]) - a[i] - 1;
  }

  vector<vector<int>> divs(mxt + 1), who(mxt + 1);
  for (int i = 1; i <= mxt; i++) {
    for (int j = i; j <= mxt; j += i) {
      divs[j].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (when[i] <= mxt) {
      who[when[i]].push_back(i);
    }
  }
  oset<pair<int, int>> s;
  for (int i = 1; i <= n; i++) {
    s.insert({a[i], i});
  }
  for (int i = 1; i <= mxt; i++) {
    for (auto &j : divs[i]) {
      for (auto &it : who[j]) {
        s.erase({a[it], it});
        a[it] += jump[it];
        s.insert({a[it], it});
      }
    }
    for (auto &it : questions[i]) {
      int l = it.l;
      int r = it.r;
      int ret = s.order_of_key(make_pair(r, n + 1)) - s.order_of_key(make_pair(l - 1, n + 1));
      sol[it.id] = ret + (l <= i && i <= r);
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << sol[i] << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 37 ms 29392 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12244 KB Output is correct
2 Correct 6 ms 12244 KB Output is correct
3 Correct 6 ms 12244 KB Output is correct
4 Correct 6 ms 12216 KB Output is correct
5 Correct 7 ms 12244 KB Output is correct
6 Correct 7 ms 12248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 37 ms 29392 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -