Submission #5496562


Source Code Expand

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

struct {
    int N;
    vector<long long> dat;

    void init(int n) {
      N = 1;
      while(N < n) N *= 2;
      dat.resize(2*N-1, 0);
    }

    // add [a, b) by x
    void add(int a, int b, long long x) {
      return add(a, b, x, 0, 0, N);
    }
    void add(int a, int b, ll x, int k, int l, int r) {
      if (r <= a || b <= l) return;
      if (a <= l && r <= b) {
        dat[k] += x;
        return;
      }
      int m = (l+r)/2;
      add(a, b, x, k*2+1, l, m);
      add(a, b, x, k*2+2, m, r);
    }

    // return k
    long long query(int k) {
      k += N-1;
      ll ret = dat[k];
      while(k > 0) {
        k = (k-1)/2;
        ret += dat[k];
      }
      return ret;
    }
} S;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  S.init(m);
  vector<P> vec;
  rep(i, n) {
    ll l, r; cin >> l >> r;
    vec.emplace_back(r-l, l*mod+r);
  }

  sort(vec.begin(), vec.end());
  int now = 1;
  rep(i, n) {
    P p = vec[i];
    ll l = vec[i].second/mod;
    ll r = vec[i].second%mod;
    ll range = vec[i].first+1;
    while(now <= range && now <= m) {
      ll ans = n-i;
      for(int j=now; j<=m; j+=now) {
        ans += S.query(j);
      }
      cout << ans << '\n';
      now++;
    }
    S.add(l, r+1, 1);
  }

  while(now <= m) {
    ll ans = 0;
    for(int j=now; j<=m; j+=now) {
      ans += S.query(j);
    }
    cout << ans << '\n';
    now++;
  }

}

Submission Info

Submission Time
Task E - Snuke Line
User aajisaka
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2134 Byte
Status WA
Exec Time 159 ms
Memory 12652 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 37
WA × 2
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 2 ms 384 KB
03.txt AC 1 ms 256 KB
04.txt WA 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt WA 1 ms 256 KB
10.txt AC 1 ms 256 KB
11.txt AC 127 ms 11372 KB
12.txt AC 156 ms 11372 KB
13.txt AC 108 ms 9452 KB
14.txt AC 98 ms 10476 KB
15.txt AC 98 ms 10604 KB
16.txt AC 121 ms 9580 KB
17.txt AC 155 ms 11500 KB
18.txt AC 92 ms 9708 KB
19.txt AC 157 ms 12652 KB
20.txt AC 156 ms 12396 KB
21.txt AC 156 ms 11116 KB
22.txt AC 156 ms 10732 KB
23.txt AC 156 ms 10732 KB
24.txt AC 135 ms 12140 KB
25.txt AC 98 ms 9196 KB
26.txt AC 90 ms 10092 KB
27.txt AC 152 ms 10988 KB
28.txt AC 110 ms 9324 KB
29.txt AC 159 ms 11500 KB
30.txt AC 109 ms 9964 KB
31.txt AC 133 ms 11500 KB
32.txt AC 101 ms 9324 KB
33.txt AC 94 ms 9836 KB
34.txt AC 136 ms 11628 KB
35.txt AC 136 ms 12012 KB
36.txt AC 1 ms 256 KB
37.txt AC 28 ms 2560 KB