結果

問題 No.2643 Many Range Sums Problems
ユーザー 👑 hos.lyrichos.lyric
提出日時 2024-02-19 21:58:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 8,000 ms
コード長 2,681 bytes
コンパイル時間 1,280 ms
コンパイル使用メモリ 116,120 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-02-19 21:58:17
合計ジャッジ時間 6,638 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 124 ms
6,548 KB
testcase_04 AC 100 ms
6,548 KB
testcase_05 AC 98 ms
6,548 KB
testcase_06 AC 144 ms
6,548 KB
testcase_07 AC 138 ms
6,548 KB
testcase_08 AC 123 ms
6,548 KB
testcase_09 AC 144 ms
6,548 KB
testcase_10 AC 119 ms
6,548 KB
testcase_11 AC 93 ms
6,548 KB
testcase_12 AC 365 ms
6,548 KB
testcase_13 AC 164 ms
6,548 KB
testcase_14 AC 124 ms
6,548 KB
testcase_15 AC 130 ms
6,548 KB
testcase_16 AC 110 ms
6,548 KB
testcase_17 AC 118 ms
6,548 KB
testcase_18 AC 52 ms
6,548 KB
testcase_19 AC 8 ms
6,548 KB
testcase_20 AC 31 ms
6,548 KB
testcase_21 AC 7 ms
6,548 KB
testcase_22 AC 63 ms
6,548 KB
testcase_23 AC 118 ms
6,548 KB
testcase_24 AC 195 ms
6,548 KB
testcase_25 AC 187 ms
6,548 KB
testcase_26 AC 18 ms
6,548 KB
testcase_27 AC 20 ms
6,548 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 133 ms
6,548 KB
testcase_31 AC 134 ms
6,548 KB
testcase_32 AC 385 ms
6,548 KB
testcase_33 AC 373 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


// floor(a / b)
Int divFloor(Int a, Int b) {
  return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}

// ceil(a / b)
Int divCeil(Int a, Int b) {
  return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}

int N;
Int K;
vector<int> R;
vector<Int> X;

int main() {
  for (; ~scanf("%d%lld", &N, &K); ) {
    R.resize(N);
    X.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d%lld", &R[i], &X[i]);
    }
    
    for (int i0 = 0; i0 < N; ++i0) {
      // a + b t
      vector<Int> as(N), bs(N);
      vector<Int> asSum(N + 1, 0), bsSum(N + 1, 0);
      for (int i = N; --i >= 0; ) {
        if (i0 != i) {
          as[i] = X[i] - (asSum[i + 1] - asSum[R[i]]);
          bs[i] = 0    - (bsSum[i + 1] - bsSum[R[i]]);
        } else {
          as[i] = 0;
          bs[i] = 1;
        }
        asSum[i] = as[i] + asSum[i + 1];
        bsSum[i] = bs[i] + bsSum[i + 1];
      }
// cerr<<"as = "<<as<<endl;
// cerr<<"bs = "<<bs<<endl;
      bool ans = true;
      Int lb = 0, ub = K;
      for (int i = 0; i < N; ++i) {
        if (bs[i] < 0) {
          chmax(lb, divCeil(K - as[i], bs[i]));
          chmin(ub, divFloor(0 - as[i], bs[i]));
        } else if (bs[i] > 0) {
          chmax(lb, divCeil(0 - as[i], bs[i]));
          chmin(ub, divFloor(K - as[i], bs[i]));
        } else {
          ans = ans && (0 <= as[i] && as[i] <= K);
        }
      }
      ans = ans && (lb <= ub);
      puts(ans ? "Yes" : "No");
    }
  }
  return 0;
}
0