結果

問題 No.2223 Merged Med
ユーザー stoqstoq
提出日時 2023-02-06 09:20:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,424 bytes
コンパイル時間 2,377 ms
コンパイル使用メモリ 212,476 KB
実行使用メモリ 43,328 KB
最終ジャッジ日時 2023-09-26 17:54:57
合計ジャッジ時間 10,274 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 204 ms
40,928 KB
testcase_16 WA -
testcase_17 AC 119 ms
27,808 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 392 ms
42,804 KB
testcase_22 WA -
testcase_23 AC 399 ms
43,092 KB
testcase_24 AC 399 ms
42,760 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 405 ms
42,816 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 197 ms
43,324 KB
testcase_31 AC 122 ms
42,012 KB
testcase_32 WA -
testcase_33 AC 344 ms
42,952 KB
testcase_34 AC 275 ms
43,328 KB
testcase_35 AC 200 ms
42,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;

struct S {
  int lmax, rmax, max, sum;
  S(int a = 0) { lmax = rmax = max = sum = a; }
};
S op(S s, S t) {
  S res;
  res.lmax = max(s.lmax, s.sum + t.lmax);
  res.rmax = max(t.rmax, s.rmax + t.sum);
  res.max = max({s.max, t.max, s.rmax + t.lmax});
  res.sum = s.sum + t.sum;
  return res;
}
S e() { return S(0); }

int main() {
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
  vector<int> l(q), r(q);
  for (int i = 0; i < q; i++) cin >> l[i] >> r[i], l[i]--;

  vector<vector<int>> a_idx(n);
  for (int i = 0; i < n; i++) a_idx[a[i]].push_back(i);
  vector<int> lo(q, -1), hi(q, n);
  vector<queue<int>> mi_num(n);
  for (int i = 0; i < q; i++) mi_num[(lo[i] + hi[i]) / 2].push(i);

  int ans_cnt = 0;
  while (ans_cnt < q) {
    atcoder::segtree<S, op, e> seg(vector<S>(n, 1));
    for (int mi = 0; mi < n; mi++) {
      for (auto i : a_idx[mi]) seg.set(i, S(-1));
      while (not mi_num[mi].empty()) {
        int i = mi_num[mi].front();
        mi_num[mi].pop();

        S s = seg.prod(l[i], r[i]);
        if (s.sum - s.max + 1 < 0)
          hi[i] = mi;
        else
          lo[i] = mi;

        if (hi[i] - lo[i] > 1)
          mi_num[lo[i] + (hi[i] - lo[i]) / 2].push(i);
        else
          ans_cnt++;
      }
    }
  }
  for (int i = 0; i < q; i++) cout << hi[i] + 1 << "\n";
}
0