結果

問題 No.489 株に挑戦
ユーザー vjudge1
提出日時 2025-01-28 20:59:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,481 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 161,676 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-28 20:59:08
合計ジャッジ時間 3,716 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:17: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         freopen ("stock.in", "r", stdin); freopen ("stock.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:39:51: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         freopen ("stock.in", "r", stdin); freopen ("stock.out", "w", stdout);
      |                                           ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:40:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |         scanf ("%lld%lld%lld", &n, &d, &k);
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:41:46: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |         for (int i = 1; i <= n; i ++ ) scanf ("%lld", &a[i]);
      |                                        ~~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 # define int long long
# define lc u << 1
# define rc u << 1 | 1
# define fi first
# define se second
const int N = 100005;

int n, d, k;
int a[N];
struct SparseTable
{
    struct node
    {
    	int mx, id;
    	bool operator < (const node &t) const { return mx != t.mx ? mx < t.mx : id < t.id; }
    } st[N][35];
    int lg[N];
    void init ()
    {
        lg[1] = 0; for (int i = 2; i <= n; i ++ ) lg[i] = lg[i >> 1] + 1;
        for (int i = 0; i <= n; i ++ ) st[i][0] = {a[i], i};
        for (int j = 1; j <= 30; j ++ )
        {
        	for (int i = 0; i + (1 << j) - 1 <= n; i ++ )
        		st[i][j] = max (st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
		}
    }
    node query (int l, int r)
    {
    	int k = lg[r - l + 1];
        return max (st[l][k], st[r - (1 << k) + 1][k]);
    }
} ST;
signed main ()
{
	freopen ("stock.in", "r", stdin); freopen ("stock.out", "w", stdout);
	scanf ("%lld%lld%lld", &n, &d, &k);
	for (int i = 1; i <= n; i ++ ) scanf ("%lld", &a[i]);
    ST.init ();
    int ans = 0;
    int idl = 0, idr = 0;
    for (int i = 1; i <= n; i ++ )
    {
        int l = min (i + 1, n), r = min (i + d, n);
        auto res = ST.query(l, r);
        if (res.mx - a[i] > ans)
        {
            ans = res.mx - a[i];
            idl = i - 1, idr = res.id - 1;
        }
    }
    if (!ans) printf ("0\n");
    else printf ("%lld\n%lld %lld", ans * k, idl, idr);
    return 0;
}
0