結果

問題 No.1234 典型RMQ
ユーザー koba-e964koba-e964
提出日時 2016-10-21 15:06:50
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,776 bytes
コンパイル時間 1,224 ms
コンパイル使用メモリ 54,812 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-27 06:33:23
合計ジャッジ時間 6,888 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
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 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <iostream>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;

const int B = 317;
const int N = 100489;
const int K = N / B; // 317
ll a[N];
ll delay[B];
ll mi[B];

int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  assert (1 <= n && n <= 100000);
  REP(i, 0, n) {
    cin >> a[i];
    assert (a[i] >= -1e10 && a[i] <= 1e10);
  }
  REP(i, 0, B) {
    ll m = a[i * K];
    REP(j, 1, K) {
      m = min(m, a[i * K + j]);
    }
    mi[i] = m;
  }
  int q;
  cin >> q;
  assert (1 <= q && q <= 100000);
  REP(i, 0, q) {
    int k, l, r;
    ll c;
    assert (cin >> k >> l >> r >> c);
    assert (k == 1 || k == 2);
    assert (1 <= l && l <= r && r <= n);
    assert (-10000 <= c && c <= 10000);
    l--; // [l,r)
    int l_boundary = l / K;
    int r_boundary = r / K;
    // [l,r) = [l,K*l_boundary) + [K*l_boundary,K*r_boundary) + [K*r_boundary,r)
    if (k == 1) { // update interval
      REP(i, l, K * l_boundary) {
	a[i] += c;
      }
      if (l_boundary >= 1) {
	ll m = a[K * (l_boundary - 1)];
	REP(i, 0, K) {
	  m = min(m, a[K * (l_boundary - 1) + i]);
	}
	mi[l_boundary - 1] = m;
      }
      REP(i, l_boundary, r_boundary) {
	delay[i] += c;
      }
      REP(i, K * r_boundary, r) {
	a[i] += c;
      }
      if (r_boundary <= n - 1) {
	ll m = a[K * r_boundary];
	REP(i, 0, K) {
	  m = min(m, a[K * r_boundary + i]);
	}
	mi[r_boundary] = m;
      }
    }
    if (k == 2) {
      ll m = 1e16;
      REP(i, l, K * l_boundary) {
        m = min(m, a[i] + delay[i / K]);
      }
      REP(i, l_boundary, r_boundary) {
	m = min(m, mi[i] + delay[i]);
      }
      REP(i, K * r_boundary, r) {
	m = min(m, a[i] + delay[i / K]);
      }
      cout << m << endl;
    }
  }
}
0