Submission #3009047


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct M {
  using T = int;
  using U = int;
  static void ap(T& a, const U& g) { a += g; }
  // static void ap(U& f, const U& g) { f += g; }
  static constexpr U id() { return 0; }
};

template<class M> struct ST {
  using T = typename M::T;
  using U = typename M::U;
  int n;
  V<T> t;
  V<U> u;

  ST(int n) : n(n) {
    t.assign(n, 0);
    u.assign(n, M::id());
  }

  void _ap(int i, const U& f) {
    if (i < n) M::ap(u[i], f);
    else M::ap(t[i - n], f);
  }

  T get(int i) {
    T res = t[i];
    for (i += n; i >>= 1;) M::ap(res, u[i]);
    return res;
  }

  void set(int l, int r, const U& f) {
    stack<int> s;
    for (int i = l + n; i >>= 1;) s.push(i);
    for (int i = r + n - 1; i >>= 1;) s.push(i);
    while (!s.empty()) {
      int i = s.top(); s.pop();
      _ap(2 * i, u[i]);
      _ap(2 * i + 1, u[i]);
      u[i] = M::id();
    }
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) _ap(l++, f);
      if (r & 1) _ap(--r, f);
    }
  }
};

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  struct seg { int l, r; };
  V<seg> a(n); for (int i = 0; i < n; i++) cin >> a[i].l >> a[i].r;
  sort(a.begin(), a.end(), [](seg a, seg b) { return a.r - a.l < b.r - b.l; });
  ST<M> res(m + 1), st(m + 1);
  int i = 0;
  for (int d = 1; d < m + 1; d++) {
    while (i < n and a[i].r - a[i].l + 1 <= d) {
      st.set(a[i].l, a[i].r + 1, 1);
      res.set(1, d, 1);
      i++;
    }
    for (int x = 0; x < m + 1; x += d) res.set(d, d + 1, st.get(x));
  }
  for (int d = 1; d < m + 1; d++) cout << res.get(d) << '\n';
}

Submission Info

Submission Time
Task E - Snuke Line
User risujiroh
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2038 Byte
Status AC
Exec Time 715 ms
Memory 4864 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 39
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt
All 00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 256 KB
00_example_02.txt AC 1 ms 256 KB
01.txt AC 1 ms 256 KB
02.txt AC 3 ms 256 KB
03.txt AC 2 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 4 ms 256 KB
06.txt AC 4 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 3 ms 256 KB
09.txt AC 2 ms 256 KB
10.txt AC 1 ms 256 KB
11.txt AC 428 ms 3456 KB
12.txt AC 709 ms 4736 KB
13.txt AC 268 ms 2816 KB
14.txt AC 276 ms 2688 KB
15.txt AC 277 ms 2688 KB
16.txt AC 373 ms 3200 KB
17.txt AC 696 ms 4736 KB
18.txt AC 261 ms 2688 KB
19.txt AC 708 ms 4736 KB
20.txt AC 711 ms 4736 KB
21.txt AC 712 ms 4736 KB
22.txt AC 715 ms 4736 KB
23.txt AC 715 ms 4736 KB
24.txt AC 671 ms 4480 KB
25.txt AC 327 ms 2944 KB
26.txt AC 266 ms 2688 KB
27.txt AC 684 ms 4608 KB
28.txt AC 337 ms 2816 KB
29.txt AC 699 ms 4608 KB
30.txt AC 340 ms 2816 KB
31.txt AC 688 ms 4864 KB
32.txt AC 351 ms 2816 KB
33.txt AC 280 ms 2688 KB
34.txt AC 682 ms 4864 KB
35.txt AC 685 ms 4864 KB
36.txt AC 1 ms 256 KB
37.txt AC 422 ms 2048 KB