結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー ei1333333ei1333333
提出日時 2022-06-17 22:55:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 3,000 ms
コード長 4,117 bytes
コンパイル時間 5,417 ms
コンパイル使用メモリ 263,336 KB
実行使用メモリ 28,804 KB
最終ジャッジ日時 2024-04-17 15:16:40
合計ジャッジ時間 12,639 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 9 ms
12,672 KB
testcase_03 AC 104 ms
16,384 KB
testcase_04 AC 118 ms
13,952 KB
testcase_05 AC 90 ms
12,416 KB
testcase_06 AC 141 ms
19,252 KB
testcase_07 AC 162 ms
19,328 KB
testcase_08 AC 116 ms
15,488 KB
testcase_09 AC 149 ms
20,736 KB
testcase_10 AC 133 ms
14,592 KB
testcase_11 AC 77 ms
9,728 KB
testcase_12 AC 145 ms
15,488 KB
testcase_13 AC 85 ms
10,112 KB
testcase_14 AC 93 ms
10,880 KB
testcase_15 AC 87 ms
10,368 KB
testcase_16 AC 113 ms
16,768 KB
testcase_17 AC 221 ms
23,168 KB
testcase_18 AC 192 ms
22,144 KB
testcase_19 AC 229 ms
23,936 KB
testcase_20 AC 49 ms
12,416 KB
testcase_21 AC 60 ms
16,436 KB
testcase_22 AC 105 ms
11,136 KB
testcase_23 AC 55 ms
11,904 KB
testcase_24 AC 76 ms
9,088 KB
testcase_25 AC 193 ms
18,432 KB
testcase_26 AC 200 ms
21,632 KB
testcase_27 AC 37 ms
6,528 KB
testcase_28 AC 99 ms
18,688 KB
testcase_29 AC 210 ms
24,096 KB
testcase_30 AC 160 ms
21,964 KB
testcase_31 AC 91 ms
18,688 KB
testcase_32 AC 272 ms
27,776 KB
testcase_33 AC 251 ms
28,672 KB
testcase_34 AC 240 ms
28,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;

using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in: v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e: t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

/**
 * @brief Binary-Indexed-Tree(BIT)
 * @docs docs/binary-indexed-tree.md
 */
template< typename T >
struct BinaryIndexedTree {
private:
  vector< T > data;

public:
  BinaryIndexedTree() = default;

  explicit BinaryIndexedTree(size_t sz) : data(sz + 1, 0) {}

  explicit BinaryIndexedTree(const vector< T > &vs) : data(vs.size() + 1, 0) {
    for(size_t i = 0; i < vs.size(); i++) data[i + 1] = vs[i];
    for(size_t i = 1; i < data.size(); i++) {
      size_t j = i + (i & -i);
      if(j < data.size()) data[j] += data[i];
    }
  }

  void add(int k, const T &x) {
    for(++k; k < (int) data.size(); k += k & -k) data[k] += x;
  }

  T fold(int r) const {
    T ret = T();
    for(; r > 0; r -= r & -r) ret += data[r];
    return ret;
  }

  T fold(int l, int r) const {
    return fold(r) - fold(l);
  }

  int lower_bound(T x) const {
    int i = 0;
    for(int k = 1 << (__lg(data.size() - 1) + 1); k > 0; k >>= 1) {
      if(i + k < data.size() && data[i + k] < x) {
        x -= data[i + k];
        i += k;
      }
    }
    return i;
  }

  int upper_bound(T x) const {
    int i = 0;
    for(int k = 1 << (__lg(data.size() - 1) + 1); k > 0; k >>= 1) {
      if(i + k < data.size() && data[i + k] <= x) {
        x -= data[i + k];
        i += k;
      }
    }
    return i;
  }
};

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector< vector< pair< int, int > > > add(N + 1);
  vector< int > C(K);
  for(int i = 0; i < K; i++) {
    int l, r, h;
    cin >> l >> r >> C[i] >> h;
    --l;
    add[l].emplace_back(h, i);
    add[r].emplace_back(-h, i);
  }
  vector< vector< pair< int64, int > > > que(N);
  for(int i = 0; i < Q; i++) {
    int x;
    int64 y;
    cin >> x >> y;
    --x;
    que[x].emplace_back(y, i);
  }
  BinaryIndexedTree< int64 > bit(K);
  vector< int > ans(Q, -1);
  for(int x = 0; x < N; x++) {
    for(auto&[h, i]: add[x]) {
      bit.add(i, h);
    }
    for(auto&[y, i]: que[x]) {
      if(bit.fold(K) < y) continue;
      ans[i] = C[bit.lower_bound(y - 1)];
    }
  }
  for(auto &p: ans) cout << p << "\n";
}
0