結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー tnakao0123tnakao0123
提出日時 2022-06-20 17:49:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 275 ms / 3,000 ms
コード長 2,692 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 60,124 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-04-21 07:02:27
合計ジャッジ時間 8,860 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
17,920 KB
testcase_01 AC 6 ms
17,664 KB
testcase_02 AC 6 ms
17,920 KB
testcase_03 AC 109 ms
23,808 KB
testcase_04 AC 132 ms
25,536 KB
testcase_05 AC 94 ms
23,296 KB
testcase_06 AC 152 ms
27,136 KB
testcase_07 AC 173 ms
27,776 KB
testcase_08 AC 127 ms
25,764 KB
testcase_09 AC 148 ms
26,988 KB
testcase_10 AC 134 ms
25,728 KB
testcase_11 AC 79 ms
22,016 KB
testcase_12 AC 158 ms
27,008 KB
testcase_13 AC 90 ms
23,888 KB
testcase_14 AC 95 ms
22,912 KB
testcase_15 AC 92 ms
23,704 KB
testcase_16 AC 120 ms
25,216 KB
testcase_17 AC 238 ms
30,976 KB
testcase_18 AC 215 ms
29,824 KB
testcase_19 AC 227 ms
30,976 KB
testcase_20 AC 44 ms
20,352 KB
testcase_21 AC 62 ms
21,904 KB
testcase_22 AC 106 ms
24,576 KB
testcase_23 AC 56 ms
21,608 KB
testcase_24 AC 78 ms
22,144 KB
testcase_25 AC 201 ms
29,440 KB
testcase_26 AC 208 ms
30,208 KB
testcase_27 AC 40 ms
19,948 KB
testcase_28 AC 89 ms
23,808 KB
testcase_29 AC 209 ms
28,128 KB
testcase_30 AC 155 ms
26,104 KB
testcase_31 AC 97 ms
23,936 KB
testcase_32 AC 275 ms
33,612 KB
testcase_33 AC 275 ms
34,688 KB
testcase_34 AC 250 ms
34,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1982.cc:  No.1982 [Cherry 4th Tune B] 絶険 - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_K = 200000;
const int MAX_QN = 200000;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,ll> pil;
typedef vector<pil> vpil;

template <typename T>
struct BIT {
  int n;
  vector<T> bits;
  
  BIT() {}
  BIT(int _n) { init(_n); }

  void init(int _n) {
    n = _n;
    bits.assign(n + 1, 0);
  }

  T sum(int x) {
    x = min(x, n);
    T s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, T v) {
    if (x <= 0) return;
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }

  int lower_bound(T v) {
    int	k = 1;
    while ((k << 1) <= n) k <<=	1;
    int	x = 0;
    for	(; k > 0; k >>= 1)
      if (x + k <= n && bits[x + k] < v) {
        x += k;
        v -= bits[x];
      }
    return x + 1;
  }
};

template <typename T>
struct BIT2D {
  int n;
  vector<BIT<T> > bits;
  
  BIT2D() {}
  BIT2D(int _ny, int _nx) { init(_ny, _nx); }

  void init(int _ny, int _nx) {
    n = _ny;
    bits.assign(n + 1, BIT<T>());
    for (int y = 1; y <= n; y++) bits[y].init(_nx);
  }

  T sum(int y, int x) {
    y = min(y, n);
    T s = 0;
    while (y > 0) {
      s += bits[y].sum(x);
      y -= (y & -y);
    }
    return s;
  }

  void add(int y, int x, T v) {
    if (y <= 0) return;
    while (y <= n) {
      bits[y].add(x, v);
      y += (y & -y);
    }
  }
};


/* global variables */

int cs[MAX_K], hs[MAX_K], qcs[MAX_QN];
vi avs[MAX_N], rvs[MAX_N + 1];
vpil qvs[MAX_N];
BIT<ll> bit;

/* subroutines */

/* main */

int main() {
  int n, k, qn;
  scanf("%d%d%d", &n, &k, &qn);

  for (int i = 0; i < k; i++) {
    int li, ri;
    scanf("%d%d%d%d", &li, &ri, cs + i, hs + i), li--;

    avs[li].push_back(i);
    rvs[ri].push_back(i);
  }

  for (int i = 0; i < qn; i++) {
    int iq;
    ll xq;
    scanf("%d%lld", &iq, &xq), iq--;

    qvs[iq].push_back(pil(i, xq));
  }

  bit.init(k);

  for (int i = 0; i < n; i++) {
    for (auto u: rvs[i]) bit.add(u + 1, -hs[u]);
    for (auto u: avs[i]) bit.add(u + 1, hs[u]);

    ll sum = bit.sum(k);
    //for (int j = 1; j <= k; j++)
    //printf("%lld%c", bit.sum(j), (j < k) ? ' ' : '\n');

    for (auto qx: qvs[i]) {
      int qi = qx.first;
      ll x = qx.second;

      qcs[qi] = -1;
      if (sum >= x) {
	int j = bit.lower_bound(x);
	//printf(" i=%d, x=%lld -> j=%d\n", i, x, j);
	if (j > 0) qcs[qi] = cs[j - 1];
      }
    }
  }

  for (int i = 0; i < qn; i++) printf("%d\n", qcs[i]);
  return 0;
}
0