結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー tnakao0123tnakao0123
提出日時 2022-06-20 17:42:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,688 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 60,248 KB
実行使用メモリ 34,796 KB
最終ジャッジ日時 2024-04-21 06:56:21
合計ジャッジ時間 10,808 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
17,792 KB
testcase_01 AC 11 ms
17,792 KB
testcase_02 AC 11 ms
17,920 KB
testcase_03 AC 101 ms
23,936 KB
testcase_04 AC 134 ms
25,668 KB
testcase_05 AC 98 ms
23,424 KB
testcase_06 AC 155 ms
27,008 KB
testcase_07 AC 183 ms
27,776 KB
testcase_08 AC 129 ms
25,760 KB
testcase_09 AC 156 ms
27,008 KB
testcase_10 AC 143 ms
25,600 KB
testcase_11 AC 84 ms
22,016 KB
testcase_12 AC 156 ms
26,904 KB
testcase_13 AC 98 ms
24,020 KB
testcase_14 AC 102 ms
22,656 KB
testcase_15 AC 98 ms
23,552 KB
testcase_16 AC 131 ms
25,216 KB
testcase_17 AC 258 ms
31,104 KB
testcase_18 AC 209 ms
29,824 KB
testcase_19 AC 237 ms
30,976 KB
testcase_20 AC 51 ms
20,480 KB
testcase_21 AC 69 ms
22,032 KB
testcase_22 AC 116 ms
24,448 KB
testcase_23 AC 68 ms
21,600 KB
testcase_24 AC 82 ms
22,144 KB
testcase_25 AC 218 ms
29,184 KB
testcase_26 AC 247 ms
30,032 KB
testcase_27 AC 51 ms
19,872 KB
testcase_28 AC 109 ms
23,936 KB
testcase_29 WA -
testcase_30 AC 166 ms
26,100 KB
testcase_31 WA -
testcase_32 AC 317 ms
33,804 KB
testcase_33 WA -
testcase_34 AC 273 ms
34,776 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];
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