結果

問題 No.489 株に挑戦
ユーザー CleyLCleyL
提出日時 2023-01-22 16:35:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 1,000 ms
コード長 2,436 bytes
コンパイル時間 1,052 ms
コンパイル使用メモリ 80,932 KB
実行使用メモリ 13,340 KB
最終ジャッジ日時 2023-09-07 02:24:46
合計ジャッジ時間 4,190 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
11,728 KB
testcase_01 AC 30 ms
8,140 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 49 ms
12,504 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 30 ms
8,080 KB
testcase_19 AC 23 ms
7,560 KB
testcase_20 AC 55 ms
12,508 KB
testcase_21 AC 14 ms
5,328 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 33 ms
8,292 KB
testcase_24 AC 63 ms
13,192 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 54 ms
13,264 KB
testcase_27 AC 72 ms
13,340 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 56 ms
13,288 KB
testcase_31 AC 54 ms
13,292 KB
testcase_32 AC 35 ms
8,344 KB
testcase_33 AC 61 ms
13,036 KB
testcase_34 AC 56 ms
12,300 KB
testcase_35 AC 24 ms
7,188 KB
testcase_36 AC 9 ms
4,396 KB
testcase_37 AC 31 ms
8,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

template< typename T, typename F>
struct SegmentTree{
  private:
    int n;
    vector<T> node;

    F f;
    T initer;

  public:
    SegmentTree(int n_, F f, T initer) : f(f),initer(initer) {
      n = 1;
      while(n < n_)n*=2;
      node.resize(2*n-1, initer);
    }

    SegmentTree(vector<T> x, F f, T initer) : f(f),initer(initer) {
      n = 1;
      while(n < x.size())n*=2;
      node.resize(2*n-1, initer);
      set(x);
    }

    void set(vector<T> x){
      for(int i = 0; n > i; i++){
        update(i,x[i]);
      }
    }

    void update(int x, T val){
      x += (n-1);

      node[x] = val;

      while(x > 0){
        x = (x-1)/2;
        node[x] = f(node[2*x+1],node[2*x+2]);
      }
    }

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

    T getf(int a,int b, int k=0, int l=0, int r=-1){
      
      if(r < 0){
        r = n-1;
      }
      if(r < a || b < l){
        return initer;
      }
      if(a <= l && r <= b){
        return node[k];
      }

      T vl = getf(a,b,2*k+1,l,(l+r)/2);
      T vr = getf(a,b,2*k+2,(l+r)/2+1,r);
      return f(vl,vr);
    }
    T operator[](int x){
      x += (n-1);
      return node[x];
    }
};

template <typename T, typename F>
SegmentTree<T, F> get_segment_tree(int N, const F &f, T initer){
  return SegmentTree<T,F>{N,f,initer};
}

template <typename T, typename F>
SegmentTree<T, F> get_segment_tree(vector<T> x, const F &f, T initer){
  return SegmentTree<T,F>{x,f, initer};
}

int main(){
  long long n,d,k;cin>>n>>d>>k;
  vector<pair<long long,int>> A(n);
  for(int i = 0; n > i; i++){
    cin>>A[i].first;
    A[i].second = i;
  }
  auto seg = get_segment_tree(A,[](pair<long long,int> a, pair<long long,int> b){
        if(a.first == b.first){
          if(a.second < b.second)return a;
          else return b;
        }else{
          if(a.first < b.first)return a;
          else return b;
        }
      }, {1000000000,-1});
  long long ans = 0;
  pair<int,int> ansi = {0,0};
  for(int i = 1; n > i; i++){
    auto x = seg.getf(max(0LL,i-d),i-1);
    if(ans < A[i].first-x.first){
      ans = A[i].first-x.first;
      ansi = make_pair(x.second, A[i].second);
    }
  }
  cout << ans*k << endl;
  if(ans)cout << ansi.first << " " << ansi.second << endl;

}

0