結果

問題 No.1055 牛歩
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-05-15 22:50:32
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 5,541 bytes
コンパイル時間 932 ms
コンパイル使用メモリ 108,148 KB
実行使用メモリ 18,772 KB
最終ジャッジ日時 2023-09-04 07:49:54
合計ジャッジ時間 13,670 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 349 ms
12,824 KB
testcase_02 AC 388 ms
14,784 KB
testcase_03 AC 403 ms
14,976 KB
testcase_04 AC 420 ms
14,972 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 246 ms
14,828 KB
testcase_08 WA -
testcase_09 AC 200 ms
13,624 KB
testcase_10 AC 228 ms
13,304 KB
testcase_11 WA -
testcase_12 AC 36 ms
9,748 KB
testcase_13 AC 37 ms
10,536 KB
testcase_14 AC 378 ms
13,172 KB
testcase_15 AC 380 ms
12,544 KB
testcase_16 AC 217 ms
11,928 KB
testcase_17 WA -
testcase_18 AC 217 ms
11,956 KB
testcase_19 WA -
testcase_20 AC 298 ms
14,896 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 447 ms
15,000 KB
testcase_24 AC 449 ms
15,004 KB
testcase_25 AC 272 ms
16,096 KB
testcase_26 AC 267 ms
16,868 KB
testcase_27 AC 275 ms
15,784 KB
testcase_28 AC 272 ms
15,520 KB
testcase_29 AC 200 ms
15,556 KB
testcase_30 AC 274 ms
15,576 KB
testcase_31 AC 70 ms
4,576 KB
testcase_32 AC 38 ms
4,552 KB
testcase_33 AC 73 ms
4,536 KB
testcase_34 AC 22 ms
4,564 KB
testcase_35 AC 74 ms
4,508 KB
testcase_36 AC 73 ms
4,516 KB
testcase_37 AC 30 ms
6,088 KB
testcase_38 AC 49 ms
4,568 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 13 ms
4,380 KB
testcase_41 AC 5 ms
4,376 KB
testcase_42 AC 9 ms
4,380 KB
testcase_43 AC 3 ms
4,380 KB
testcase_44 AC 12 ms
4,376 KB
testcase_45 AC 14 ms
4,384 KB
testcase_46 AC 4 ms
4,380 KB
testcase_47 AC 14 ms
4,384 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 3 ms
4,380 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 2 ms
4,380 KB
testcase_60 AC 2 ms
4,384 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 2 ms
4,380 KB
testcase_66 AC 2 ms
4,380 KB
testcase_67 AC 1 ms
4,376 KB
testcase_68 AC 1 ms
4,380 KB
testcase_69 AC 1 ms
4,380 KB
testcase_70 AC 2 ms
4,380 KB
testcase_71 AC 1 ms
4,380 KB
testcase_72 WA -
testcase_73 AC 2 ms
4,376 KB
testcase_74 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

// T, S: monoid
// opTT: T * T -> T
// opST: S * T * int -> T
//   (s t_a) ... (s t_{b-1}) = opST(s, t_a ... t_{b-1}, b - a)
// opSS: S * S -> S
// query(a, b, s): t_a <- s t_a, ..., t_{b-1} <- s t_{b-1};
//   returns t_a ... t_{b-1}
class SegmentTree(T, S, alias opTT, alias opST, alias opSS) {
  import std.functional : binaryFun;
  alias opTTFun = binaryFun!opTT;
  alias opSTFun = opST;
  alias opSSFun = binaryFun!opSS;
  const(T) idT;
  const(S) idS;

  int n;
  T[] ts;
  S[] ss;
  this(int n_, const(T) idT, const(S) idS) {
    this.idT = idT;
    this.idS = idS;
    for (n = 1; n < n_; n <<= 1) {}
    ts = new T[n << 1];
    ss = new S[n << 1];
    ts[] = idT;
    ss[] = idS;
  }
  ref T at(int a) {
    return ts[n + a];
  }
  void build() {
    foreach_reverse (a; 1 .. n) ts[a] = opTTFun(ts[a << 1], ts[a << 1 | 1]);
  }
  T query(int a, int b, const(S) s) {
    return query(1, 0, n, a, b, s);
  }

 private:
  T query(int u, int l, int r, int a, int b, const(S) s) {
    if (a < l) a = l;
    if (b > r) b = r;
    if (a >= b) return idT;
    if (a == l && b == r) {
      ts[u] = opSTFun(s, ts[u], r - l);
      ss[u] = opSSFun(s, ss[u]);
      return ts[u];
    }
    const int uL = u << 1, uR = u << 1 | 1;
    const int mid = (l + r) >> 1;
    // speed-up: if (ss[u] != idS)
    {
      ts[uL] = opSTFun(ss[u], ts[uL], mid - l);
      ts[uR] = opSTFun(ss[u], ts[uR], r - mid);
      ss[uL] = opSSFun(ss[u], ss[uL]);
      ss[uR] = opSSFun(ss[u], ss[uR]);
      ss[u] = idS;
    }
    const T resL = query(uL, l, mid, a, b, s);
    const T resR = query(uR, mid, r, a, b, s);
    ts[u] = opTTFun(ts[uL], ts[uR]);
    return opTTFun(resL, resR);
  }
}



void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const M = readInt();
      auto A = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt();
      }
      const Q = readInt();
      auto B = new int[Q];
      foreach (q; 0 .. Q) {
        B[q] = readInt() - 1;
      }
      
      auto qss = new int[][M];
      foreach (q; 0 .. Q) {
        qss[B[q]] ~= q;
      }
      debug {
        writeln("qss = ", qss);
      }
      
      bool ans;
      auto seg = new SegmentTree!(int, int, max, (s, t, sz) => ((s == -2) ? t : s), max)(Q, 0, -2);
      foreach (i; 0 .. M) {
        const len = cast(int)(qss[i].length);
        qss[i] ~= Q;
        {
          const mx = seg.query(0, qss[i][0], -2);
          if (!(mx < A[i])) {
            goto failed;
          }
        }
        seg.query(0, qss[i][0], A[i]);
        int a = A[i];
        foreach (j; 0 .. len) {
          const mx = seg.query(qss[i][j], qss[i][j + 1], -2);
          if (mx < a - 1) {
            debug {
              writeln(i, " ", qss[i][j], ": -");
            }
            --a;
          } else if (mx < a + 1) {
            debug {
              writeln(i, " ", qss[i][j], ": +");
            }
            ++a;
          } else {
            goto failed;
          }
          seg.query(qss[i][j], qss[i][j + 1], a);
        }
      }
      {
        const mx = seg.query(0, Q, -2);
        if (!(mx < N + 1)) {
          goto failed;
        }
      }
      ans = true;
     failed:
      
      // debug {
if(M<=5000&&Q<=5000){
        bool brt;
        auto nums = new int[Q];
        nums[] = 0;
        foreach (i; 0 .. M) {
          const len = cast(int)(qss[i].length) - 1;
          // const len = cast(int)(qss[i].length);
          // qss[i] ~= Q;
          foreach (q; 0 .. qss[i][0]) {
            if (!(nums[q] < A[i])) {
              goto failedBrute;
            }
          }
          nums[0 .. qss[i][0]] = A[i];
          int a = A[i];
          foreach (j; 0 .. len) {
            const mx = nums[qss[i][j] .. qss[i][j + 1]].maxElement;
            if (mx < a - 1) {
              // writeln(i, " ", qss[i][j], ": -");
              --a;
            } else if (mx < a + 1) {
              // writeln(i, " ", qss[i][j], ": +");
              ++a;
            } else {
              goto failedBrute;
            }
            nums[qss[i][j] .. qss[i][j + 1]] = a;
          }
        }
        if (!(nums.maxElement < N + 1)) {
          goto failedBrute;
        }
        brt = true;
       failedBrute:
        // writeln("brt = ", brt);
        assert(brt == ans);
      }
      
      writeln(ans ? "YES" : "NO");
    }
  } catch (EOFException e) {
  }
}
0