結果

問題 No.489 株に挑戦
ユーザー mogurockermogurocker
提出日時 2017-10-25 01:06:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,451 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 167,848 KB
実行使用メモリ 134,656 KB
最終ジャッジ日時 2024-05-01 13:18:36
合計ジャッジ時間 7,503 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 76 ms
134,144 KB
testcase_03 AC 75 ms
134,220 KB
testcase_04 AC 76 ms
134,228 KB
testcase_05 WA -
testcase_06 AC 75 ms
134,272 KB
testcase_07 WA -
testcase_08 AC 75 ms
134,144 KB
testcase_09 AC 75 ms
134,272 KB
testcase_10 AC 75 ms
134,144 KB
testcase_11 AC 76 ms
134,272 KB
testcase_12 AC 76 ms
134,260 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 158 ms
134,492 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 115 ms
134,400 KB
testcase_20 AC 163 ms
134,476 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 173 ms
134,528 KB
testcase_25 AC 76 ms
134,144 KB
testcase_26 AC 177 ms
134,472 KB
testcase_27 WA -
testcase_28 AC 77 ms
134,144 KB
testcase_29 AC 76 ms
134,144 KB
testcase_30 AC 175 ms
134,528 KB
testcase_31 AC 174 ms
134,656 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 88 ms
134,304 KB
testcase_37 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, const char**)’:
main.cpp:93:9: warning: ‘l’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   93 |         if (r <= l) ma = 0;
      |         ^~
main.cpp:93:9: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;
ll d, k;

template<class V,int NV> class SegTree_Pair1 {
public:
	vector<pair<V,int> > val;
	static V const def=0;
	pair<V,int> comp(pair<V,int> l,pair<V,int> r){ return max(l,r);}
	SegTree_Pair1(){
		val.resize(NV*2);
		int i;
		FOR(i,NV) val[i+NV]=make_pair(def,i);
		for(i=NV-1;i>=1;i--) val[i]=comp(val[2*i],val[2*i+1]);
	};
	pair<V,int> getval(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l) return make_pair(def,NV);
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry]=make_pair(v,entry-NV);
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};
SegTree_Pair1<int,1<<22> st1;

template<class V,int NV> class SegTree_Pair2 {
public:
	vector<pair<V,int> > val;
	static V const def=1<<22;
	pair<V,int> comp(pair<V,int> l,pair<V,int> r){ return min(l,r);}
	SegTree_Pair2(){
		val.resize(NV*2);
		int i;
		FOR(i,NV) val[i+NV]=make_pair(def,i);
		for(i=NV-1;i>=1;i--) val[i]=comp(val[2*i],val[2*i+1]);
	};
	pair<V,int> getval(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l) return make_pair(def,NV);
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry]=make_pair(v,entry-NV);
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};
SegTree_Pair2<int,1<<22> st2;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> d >> k;
	vector<int> x(n);
	FOR(i, n) {
		cin >> x[i];
		st1.update(i, x[i]);
		st2.update(i, x[i]);
	}
	int ma = 0, l, r;
	FOR(i, n) {
		P p1 = st1.getval(i, i+d+1), p2 = st2.getval(i, i+d+1);
		if (ma < p1.first-p2.first) {
			ma = p1.first-p2.first;
			r = p1.first;
			l = p2.first;
		}
	}
	FOR(i, n) {
		if (x[i] == l) {
			l = i;
			break;
		}
	}
	FOR(i, n) {
		if (x[i] == r) {
			r = i;
			break;
		}
	}
	if (r <= l) ma = 0;
	cout << 1LL*ma*k << endl;
	if (ma > 0) cout << l << " " << r << endl;
	return 0;
}
0