結果

問題 No.489 株に挑戦
ユーザー iqueue02iqueue02
提出日時 2019-12-23 21:26:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,436 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 173,532 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2023-10-19 04:19:12
合計ジャッジ時間 4,369 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
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 AC 2 ms
4,348 KB
testcase_26 AC 38 ms
5,760 KB
testcase_27 WA -
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 WA -
testcase_31 AC 35 ms
5,760 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

template <typename T> 
struct SegmentTree {
  
  int n;
  vector<T> node;

  T f(T a, T b) {return max(a, b);}

  SegmentTree (int sz, T init = 0) {
    n = 1; while (n < sz) n <<= 1;
    node.assign(2*n, init);
  }

  void update(int k, T x) {
    k += (n - 1);
    node[k] = x;
    while (k > 0) {
      k = (k - 1) >> 1;
      node[k] = f(node[2*k+1], node[2*k+2]);
    } 
  }

  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2*k+1, l, (l+r)/2);
    T vr = query(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }

  T getvalue(int k) {
    return query(k,k+1);
  }

};

int main(){
  int n, d, k;
  cin >> n >> d >> k;
  SegmentTree<ll> seg(n);
  vector<int> x(n);
  rep(i,n) {
    cin >> x[i];
    seg.update(i,x[i]);
  }
  ll res = 0;
  int midx = -1;
  for (int i = 0; i + d < n; i++) {
    ll dif = seg.query(i,i+d+1);
    ll v = dif - seg.getvalue(i);
    if (res < v) {
      res = v;
      midx = i;
    }
  }
  cout << res * k << endl;
  if (res > 0) {
    for (int i = 0; i <= d; i++) {
      if (x[midx + i] - x[midx] == res) {
        cout << midx << " " << i << endl;
        return 0;
      }
    }
  }
  return 0;
}
0