提出 #26404277


ソースコード 拡げる

//\\//\\ * * * //\\// ||
#include <bits/stdc++.h>
using namespace std;

#define debug(...) cerr << '[' << #__VA_ARGS__ << ']' << '\n'; dbg(__VA_ARGS__);
/*/
#define debug(...) 0
//*/

template <typename T> void dbg(T a) { cerr << a << '\n'; }
template <typename T, typename U> void dbg(pair<T, U> p) { cerr << p.first << " " << p.second << '\n'; }
template <typename T>  void dbg(T a, int sz) {
  for (int i = 0; i < sz; i++) cerr << a[i] << " ";
  cerr << '\n';
}
template <typename T> void dbg(T a, int sz1, int sz2) {
  for (int i = 0; i < sz1; i++) {
    for (int j = 0; j < sz2; j++) {
      cerr << a[i][j] << " ";
    }
    cerr << '\n';
  }
}
template <typename T> void dbg(vector<T> v) {
  for (int i = 0; i < (int) v.size(); i++) {
    cerr << v[i] << " ";
  }
  cerr << '\n';
}
/*** start here! ***/

const int N = (int) 8e5 + 10;

void kill() {
  cout << "shit";
  exit(0);
}

struct node {
  long long sum = 0;
  long long add = 0;
  void apply(int l, int r, long long v) {
    sum += (r - l) * v;
    add += v;
  }
} tree[N * 4];

node unite(node a, node b) {
  node res;
  res.sum = a.sum + b.sum;
  return res;
}

void push(int x, int l, int r) {
  if (x < 0) kill();
  if (tree[x].add) {
    int mid = (l + r) >> 1;
    tree[x << 1].apply(l, mid, tree[x].add);
    tree[x << 1 | 1].apply(mid, r, tree[x].add);
    tree[x].add = 0;
  }
}

void pull(int x) {
  if (x < 0) kill();
  tree[x] = unite(tree[x << 1], tree[x << 1 | 1]);
}

node get(int x, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) {
    if (x < 0) kill();
    return tree[x];
  }
  if (rr <= l || ll >= r) {
    node def;
    def.sum = 0;
    def.add = 0;
    return def;
  }
  int mid = (l + r) >> 1;
  push(x, l, r);
  node res = unite(get(x << 1, l, mid, ll, rr), get(x << 1 | 1, mid, r, ll, rr));
  pull(x);
  return res;
}

void modify(int x, int l, int r, int ll, int rr, long long v) {
  if (ll <= l && r <= rr) {
    if (x < 0) kill();
    tree[x].apply(l, r, v);
    return;
  }
  if (rr <= l || ll >= r) {
    return;
  }
  int mid = (l + r) >> 1;
  push(x, l, r);
  modify(x << 1, l, mid, ll, rr, v);
  modify(x << 1 | 1, mid, r, ll, rr, v);
  pull(x);
  return;
}

long long a[N], b[N];
long long n, day[N], ps[N];
set<long long> s;
vector<long long> v;

int Get(long long x) {
  int low = 0, high = (int) v.size() - 1;
  while (low < high) {
    int mid = (low + high + 1) / 2;
    if (mid < 0) kill();
    if (v[mid] <= x) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  return low;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    b[i] = a[i] + b[i] - 1;
    s.insert(a[i]);
    s.insert(b[i]);
  }
  for (auto x : s) {
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  if ((int) v.size() == 1) {
    for (int i = 1; i < n; i++) {
      cout << 0 << " ";
    }
    cout << n << '\n';
    return 0;
  }
  int sz = (int) v.size();
  for (int i = 0; i < n; i++) {
    int l = Get(a[i]), r = Get(b[i]);
    if (l < 0 || r < 0) kill();
    ++ps[l];
    --ps[r];
    modify(1, 0, sz, l, r + 1, (long long) 1);
  }
  for (int i = 1; i < sz; i++) {
    ps[i] += ps[i - 1];
  }
  for (int i = 0; i < sz - 1; i++) {
    if (ps[i] < 0) kill();
    day[ps[i]] += v[i + 1] - v[i] - 1;
  }
  for (int i = 0; i < sz; i++) {
    int x = get(1, 0, sz, i, i + 1).sum;
    if (x < 0) {
      cout << "shit";
    }
    if (x < 0) kill();
    ++day[x];
  }
  for (int i = 1; i <= n; i++) {
    cout << day[i] << " ";
  }
  cout << '\n';
  return 0;
}

提出情報

提出日時
問題 D - Online games
ユーザ begging_beginner
言語 C++ (GCC 9.2.1)
得点 400
コード長 3718 Byte
結果 AC
実行時間 606 ms
メモリ 49460 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 24
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 6 ms 3464 KiB
example_01.txt AC 3 ms 3532 KiB
hand_00.txt AC 54 ms 6764 KiB
hand_01.txt AC 4 ms 3608 KiB
hand_02.txt AC 460 ms 47992 KiB
hand_03.txt AC 567 ms 49368 KiB
hand_04.txt AC 7 ms 3548 KiB
hand_05.txt AC 2 ms 3524 KiB
hand_06.txt AC 64 ms 6688 KiB
hand_07.txt AC 44 ms 5504 KiB
hand_08.txt AC 443 ms 48028 KiB
hand_09.txt AC 570 ms 49460 KiB
random_00.txt AC 246 ms 11696 KiB
random_01.txt AC 238 ms 10340 KiB
random_02.txt AC 230 ms 9948 KiB
random_03.txt AC 230 ms 9916 KiB
random_04.txt AC 234 ms 10064 KiB
random_05.txt AC 352 ms 25008 KiB
random_06.txt AC 352 ms 25020 KiB
random_07.txt AC 356 ms 24980 KiB
random_08.txt AC 587 ms 48712 KiB
random_09.txt AC 574 ms 48748 KiB
random_10.txt AC 606 ms 48720 KiB
random_11.txt AC 592 ms 48792 KiB