Submission #3009036


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.resize(n);
    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 0
Code Size 2034 Byte
Status WA
Exec Time 719 ms
Memory 4864 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 25
WA × 14
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 WA 3 ms 256 KB
03.txt AC 2 ms 256 KB
04.txt WA 1 ms 256 KB
05.txt AC 4 ms 256 KB
06.txt AC 4 ms 256 KB
07.txt WA 1 ms 256 KB
08.txt AC 3 ms 256 KB
09.txt WA 2 ms 256 KB
10.txt AC 1 ms 256 KB
11.txt WA 424 ms 3456 KB
12.txt WA 705 ms 4736 KB
13.txt WA 266 ms 2816 KB
14.txt WA 276 ms 2688 KB
15.txt WA 274 ms 2688 KB
16.txt WA 371 ms 3200 KB
17.txt WA 697 ms 4736 KB
18.txt WA 260 ms 2688 KB
19.txt AC 719 ms 4736 KB
20.txt AC 709 ms 4736 KB
21.txt AC 711 ms 4736 KB
22.txt AC 709 ms 4736 KB
23.txt AC 706 ms 4736 KB
24.txt AC 671 ms 4480 KB
25.txt AC 328 ms 2816 KB
26.txt AC 265 ms 2688 KB
27.txt AC 682 ms 4608 KB
28.txt AC 334 ms 2816 KB
29.txt AC 694 ms 4608 KB
30.txt AC 340 ms 2816 KB
31.txt AC 705 ms 4864 KB
32.txt AC 342 ms 2816 KB
33.txt AC 280 ms 2688 KB
34.txt AC 680 ms 4864 KB
35.txt AC 683 ms 4864 KB
36.txt WA 1 ms 256 KB
37.txt WA 422 ms 2048 KB