結果

問題 No.2220 Range Insert & Point Mex
ユーザー chro_96chro_96
提出日時 2023-02-17 23:17:46
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 3,626 bytes
コンパイル時間 1,167 ms
コンパイル使用メモリ 32,000 KB
実行使用メモリ 20,156 KB
最終ジャッジ日時 2024-07-19 14:28:32
合計ジャッジ時間 7,465 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
19,060 KB
testcase_01 AC 6 ms
19,036 KB
testcase_02 AC 6 ms
18,972 KB
testcase_03 WA -
testcase_04 AC 7 ms
18,988 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 6 ms
18,976 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 273 ms
19,960 KB
testcase_21 AC 267 ms
20,048 KB
testcase_22 AC 279 ms
19,984 KB
testcase_23 AC 171 ms
19,864 KB
testcase_24 AC 145 ms
19,744 KB
testcase_25 AC 117 ms
19,616 KB
testcase_26 AC 142 ms
19,884 KB
testcase_27 AC 54 ms
19,604 KB
testcase_28 AC 60 ms
19,220 KB
testcase_29 AC 60 ms
19,088 KB
testcase_30 AC 62 ms
19,112 KB
testcase_31 AC 143 ms
19,888 KB
testcase_32 AC 111 ms
19,580 KB
testcase_33 AC 113 ms
19,708 KB
testcase_34 AC 201 ms
20,116 KB
testcase_35 AC 201 ms
20,000 KB
testcase_36 AC 167 ms
19,920 KB
testcase_37 AC 170 ms
19,984 KB
testcase_38 AC 160 ms
20,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int cmp_int (const void *ap, const void *bp) {
  int a = *(int *)ap;
  int b = *(int *)bp;
  
  if (a < b) {
    return -1;
  }
  
  if (a > b) {
    return 1;
  }
  
  return 0;
}

void eval (int *t, int lazy[][2], int k, int l, int r) {
  if (lazy[k][0] <= 0) {
    return;
  }
  
  t[k] = lazy[k][0];
  if (r-l > 1) {
    if (t[2*k+1] >= lazy[k][1]-1 || lazy[2*k+1][0] >= lazy[k][1]-1) {
      lazy[2*k+1][0] = lazy[k][0];
      lazy[2*k+1][1] = t[2*k+1]+1;
    }
    if (t[2*k+2] >= lazy[k][1]-1 || lazy[2*k+2][0] >= lazy[k][1]-1) {
      lazy[2*k+2][0] = lazy[k][0];
      lazy[2*k+2][1] = t[2*k+1]+1;
    }
  }
  lazy[k][0] = 0;
  lazy[k][1] = 0;
  
  return;
}
 
void set_segt_rec (int *t, int lazy[][2], int a, int b, int val, int k, int l, int r) {
  eval(t, lazy, k, l, r);
  if (r <= a || b <= l) {
    return;
  }
  
  if (a <= l && r <= b) {
    if (t[k] >= val-1) {
      lazy[k][0] = val;
      lazy[k][1] = val;
      eval(t, lazy, k, l, r);
    }
    return;
  }
  
  set_segt_rec(t, lazy, a, b, val, 2*k+1, l, (l+r)/2);
  set_segt_rec(t, lazy, a, b, val, 2*k+2, (l+r)/2, r);
  
  t[k] = t[2*k+1];
  if (t[k] < t[2*k+2]) {
    t[k] = t[2*k+2];
  }
  
  return;
}
 
void set_segt (int *t, int lazy[][2], int a, int b, int val, int size) {
  set_segt_rec(t, lazy, a, b, val, 0, 0, size);
  return;
}
 
int max_segt_rec (int *t, int lazy[][2], int a, int b, int k, int l, int r) {
  int ans = 0;
  int tmp = 0;
  
  if (r <= a || b <= l) {
    return 0;
  }
  
  eval(t, lazy, k, l, r);
  
  if (a <= l && r <= b) {
    return t[k];
  }
  
  ans = max_segt_rec(t, lazy, a, b, 2*k+1, l, (l+r)/2);
  tmp = max_segt_rec(t, lazy, a, b, 2*k+2, (l+r)/2, r);
  
  if (ans < tmp) {
    ans = tmp;
  }
  
  return ans;
}
 
int max_segt (int *t, int lazy[][2], int a, int b, int size) {
  return max_segt_rec(t, lazy, a, b, 0, 0, size);
}

int main () {
  int n = 0;
  int l[100000] = {};
  int r[100000] = {};
  int a[100000][2] = {};
  int q = 0;
  int x[100000] = {};
  
  int res = 0;
  
  int map[300000] = {};
  int cnt = 0;
  int uniq_cnt = 1;
  
  int t[1200000] = {};
  int lazy[1200000][2] = {};
  int size = 1;
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", l+i);
    res = scanf("%d", r+i);
    res = scanf("%d", a[i]);
    map[cnt] = l[i];
    cnt++;
    map[cnt] = r[i];
    cnt++;
    a[i][1] = i;
  }
  res = scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    res = scanf("%d", x+i);
    map[cnt] = x[i];
    cnt++;
  }
  
  qsort(map, cnt, sizeof(int), cmp_int);
  for (int i = 1; i < cnt; i++) {
    if (map[i-1] != map[i]) {
      map[uniq_cnt] = map[i];
      uniq_cnt++;
    }
  }
  
  while (size <= uniq_cnt) {
    size <<= 1;
  }
  
  qsort(a, n, sizeof(int)*2, cmp_int);
  for (int i = 0; i < n; i++) {
    int lidx[2] = { 0, uniq_cnt };
    int ridx[2] = { 0, uniq_cnt };
    while (lidx[1]-lidx[0] > 1) {
      int nxt = (lidx[0]+lidx[1])/2;
      if (map[nxt] <= l[a[i][1]]) {
        lidx[0] = nxt;
      } else {
        lidx[1] = nxt;
      }
    }
    while (ridx[1]-ridx[0] > 1) {
      int nxt = (ridx[0]+ridx[1])/2;
      if (map[nxt] <= r[a[i][1]]) {
        ridx[0] = nxt;
      } else {
        ridx[1] = nxt;
      }
    }
    set_segt(t, lazy, lidx[0], ridx[1], a[i][0]+1, size);
  }
  
  for (int i = 0; i < q; i++) {
    int idx[2] = { 0, uniq_cnt };
    while (idx[1]-idx[0] > 1) {
      int nxt = (idx[0]+idx[1])/2;
      if (map[nxt] <= x[i]) {
        idx[0] = nxt;
      } else {
        idx[1] = nxt;
      }
    }
    printf("%d\n", max_segt(t, lazy, idx[0], idx[1], size));
  }
  
  return 0;
}
0