結果

問題 No.489 株に挑戦
ユーザー tottoripaper
提出日時 2017-03-26 22:05:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 40 ms / 1,000 ms
コード長 2,407 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 172,116 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-07-19 23:45:52
合計ジャッジ時間 3,698 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
using ll = long long;
using P = std::tuple<int,int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
// I want to delete this stupid solution ;(
#define sandwich(x) [](auto a, auto b){return (x)(a, b);}
template <typename T>
using F2 = std::function<T(T,T)>;
template <typename T, int N, typename F = std::plus<T>>
struct SegmentTree{
SegmentTree(T u, F f = F()){
size = 1;
while(size < N){
size <<= 1;
}
unit = u;
func = f;
init();
}
void init(){
for(int i=0;i<size;++i){
data[i+size] = unit;
}
for(int i=size-1;i>0;--i){
data[i] = func(data[i*2], data[i*2+1]);
}
}
void update(int k, int v){
k += size;
data[k] = v;
while(k > 1){
k >>= 1;
data[k] = func(data[k*2], data[k*2+1]);
}
}
inline T query(int l, int r){
return _query(l, r, 1, 0, size);
}
T _query(int a, int b, int k, int l, int r){
if(b <= l || r <= a){return unit;}
if(a <= l && r <= b){return data[k];}
int mid = (l + r) >> 1;
return func(_query(a, b, 2*k, l, mid),
_query(a, b, 2*k+1, mid, r ));
}
T unit, data[N*4];
int size;
F func;
};
ll N, D, K;
ll d[100100];
SegmentTree<ll, 100100, F2<ll>> st(0ll, sandwich(max));
int main(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> N >> D >> K;
for(int i=0;i<N;++i){
std::cin >> d[i];
st.update(i, d[i]);
}
int idx = -1;
ll res = 0ll;
for(int i=0;i<N-1;++i){
ll x = (st.query(i+1, min(i+1+D, N)) - d[i]) * K;
if(x > res){
res = x;
idx = i;
}
}
std::cout << res << std::endl;
if(res > 0){
std::cout << idx << " ";
for(int i=1;i<=D&&idx+i<N;++i){
if(d[idx+i] - d[idx] == res / K){
std::cout << (idx+i) << std::endl;
return 0;
}
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0