提出 #4498776


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/05  Problem: ABC 095 D / Link: http://abc095.contest.atcoder.jp/tasks/abc095_d  ----- */

template<typename Monoid>
struct SegmentTreeFastAry {
	using nd = typename Monoid::type;
	const int ARY_SIZE;
	vector<nd> node;
public:
	SegmentTreeFastAry(int n) : ARY_SIZE(n), node(2 * ARY_SIZE, Monoid::id()) {}
	inline void update(int i, const nd val) {
		i += ARY_SIZE; node[i] = Monoid::upd(node[i], val);
		while (i > 1) { i >>= 1;	node[i] = Monoid::op(node[i << 1], node[(i << 1) + 1]); }
	}
	inline nd query(int l, int r) {
		if (l >= r) return Monoid::id(); nd vl = Monoid::id(), vr = Monoid::id();
		for (l += ARY_SIZE, r += ARY_SIZE; l != r; l >>= 1, r >>= 1) {
			if (l & 1) vl = Monoid::op(vl, node[l++]); if (r & 1) vr = Monoid::op(node[--r], vr);
		}	return Monoid::op(vl, vr);
	}
	nd operator[](int i) { return node[i + ARY_SIZE]; }
	void debugShow() { for (int i = ARY_SIZE; i < ARY_SIZE << 1; ++i) cerr << node[i] << " "; cerr << "\n"; }
};


struct Cumusum {
	vector<LL>csum;
	Cumusum(vector<LL>&a) {
		csum.assign((int)a.size() + 1, 0);
		for (int i = 0; i < (int)a.size(); i++) {
			csum[i + 1] = csum[i] + a[i];
		}
	}
	LL query(int l, int r) {
		return csum[r] - csum[l];
	}
};
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	struct MaxUpd {
		using type = LL;
		static type id() { return 0; }
		static type op(const type&l, const type&r) {
			return max(l, r);
		}
		static type upd(const type&l, const type&r) {
			return r;
		}
	};

	LL N, C; cin >> N >> C;
	vector<LL> x(N + 2), add(N + 2);
	for (int i = 0; i < N; ++i) {
		cin >> x[i + 1] >> add[i + 1];
	}
	VL a(N + 1); {
		FOR(i, 1, N + 1) {
			a[i] = add[i] - (x[i]-x[i-1]);
		}
	}
	Cumusum cumToR(a);
	SegmentTreeFastAry<MaxUpd>segToR(N + 10); {
		FOR(i, 0, N + 1) {
			segToR.update(i, cumToR.query(0, i + 1) - x[i]);
		}
	}
	{ // rev
		FOR(i, 1, N + 1) {
			x[i] = C - x[i];
		}
		reverse(ALL(x));
		reverse(ALL(add));
	}
	VL b(N + 1); {
		FOR(i, 1, N + 1) {
			b[i] = add[i] - (x[i]-x[i-1]);
		}
	}
	Cumusum cumToL(b);
	SegmentTreeFastAry<MaxUpd> segToL(N + 10); {
		FOR(i, 0, N + 1) {
			segToL.update(i, cumToL.query(0, i + 1) - x[i]);
		}
	}

	LL ans = 0;
	FOR(i, 0, N + 1) {
		{
			LL sub = cumToR.query(0, i + 1);
			sub += max(0LL, segToL.query(0, N - i+1));
			ans = max(ans, sub);
		}
		{
			LL sub = cumToL.query(0, i + 1);
			sub += max(0LL, segToR.query(0, N - i+1));
			ans = max(ans, sub);
		}
	}



	cout << (ans) << "\n";

	return 0;
}

提出情報

提出日時
問題 D - Static Sushi
ユーザ Yang33
言語 C++14 (GCC 5.4.1)
得点 500
コード長 3526 Byte
結果 AC
実行時間 47 ms
メモリ 8064 KiB

ジャッジ結果

セット名 Sample Subtask1 Subtask2
得点 / 配点 0 / 0 300 / 300 200 / 200
結果
AC × 4
AC × 29
AC × 50
セット名 テストケース
Sample a01, a02, a03, a04
Subtask1 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29
Subtask2 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50
ケース名 結果 実行時間 メモリ
a01 AC 1 ms 256 KiB
a02 AC 1 ms 256 KiB
a03 AC 1 ms 256 KiB
a04 AC 1 ms 256 KiB
b05 AC 1 ms 256 KiB
b06 AC 1 ms 256 KiB
b07 AC 1 ms 256 KiB
b08 AC 1 ms 256 KiB
b09 AC 1 ms 256 KiB
b10 AC 1 ms 256 KiB
b11 AC 1 ms 256 KiB
b12 AC 1 ms 256 KiB
b13 AC 1 ms 256 KiB
b14 AC 1 ms 256 KiB
b15 AC 1 ms 256 KiB
b16 AC 1 ms 256 KiB
b17 AC 1 ms 256 KiB
b18 AC 1 ms 256 KiB
b19 AC 1 ms 256 KiB
b20 AC 1 ms 256 KiB
b21 AC 1 ms 256 KiB
b22 AC 1 ms 256 KiB
b23 AC 1 ms 256 KiB
b24 AC 1 ms 256 KiB
b25 AC 1 ms 256 KiB
b26 AC 1 ms 256 KiB
b27 AC 1 ms 256 KiB
b28 AC 1 ms 256 KiB
b29 AC 1 ms 256 KiB
c30 AC 38 ms 8064 KiB
c31 AC 42 ms 8064 KiB
c32 AC 47 ms 8064 KiB
c33 AC 47 ms 8064 KiB
c34 AC 47 ms 8064 KiB
c35 AC 38 ms 8064 KiB
c36 AC 46 ms 8064 KiB
c37 AC 46 ms 8064 KiB
c38 AC 45 ms 8064 KiB
c39 AC 47 ms 8064 KiB
c40 AC 46 ms 8064 KiB
c41 AC 46 ms 8064 KiB
c42 AC 46 ms 8064 KiB
c43 AC 6 ms 1024 KiB
c44 AC 47 ms 8064 KiB
c45 AC 2 ms 384 KiB
c46 AC 45 ms 8064 KiB
c47 AC 1 ms 256 KiB
c48 AC 46 ms 8064 KiB
c49 AC 45 ms 8064 KiB
c50 AC 47 ms 8064 KiB