結果
問題 |
No.489 株に挑戦
|
ユーザー |
![]() |
提出日時 | 2025-01-27 21:37:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 41 ms / 1,000 ms |
コード長 | 1,562 bytes |
コンパイル時間 | 1,832 ms |
コンパイル使用メモリ | 160,956 KB |
実行使用メモリ | 36,468 KB |
最終ジャッジ日時 | 2025-01-27 21:37:05 |
合計ジャッジ時間 | 4,160 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define endl '\n' typedef long long ll; const int N = 1e5 + 10; const int LG = 20; ll n, d, k; ll a[N]; struct Sparse_Table { ll lg[N]; struct Node { ll maxx, id; inline bool operator<(const Node &x) const { if (maxx == x.maxx) return id > x.id; return maxx < x.maxx; } } st[N][LG]; inline void init() { lg[1] = 0; for (ll i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1; for (ll i = 0; i <= n; i++) st[i][0] = {a[i], i}; for (ll p = 1; p < LG; p++) for (ll i = 0; i + (1 << p) - 1 <= n; i++) st[i][p] = max(st[i][p - 1], st[i + (1 << (p - 1))][p - 1]); } inline Node query(ll l, ll r) { ll k = lg[r - l + 1]; return max(st[l][k], st[r - (1 << k) + 1][k]); } } ST; int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> n >> d >> k; for (ll i = 1; i <= n; i++) cin >> a[i]; ST.init(); ll ans = 0, in = 0, out = 0; for (ll i = 1; i <= n; i++) { ll l = min(i + 1, n), r = min(i + d, n); auto tmp = ST.query(l, r); if (tmp.maxx - a[i] > ans) { ans = tmp.maxx - a[i]; in = i, out = tmp.id; } } if (ans == 0) cout << 0 << endl; else cout << ans * k << endl << in - 1 << " " << out - 1 << endl; return 0; }