結果

問題 No.1014 competitive fighting
ユーザー 👑 jupirojupiro
提出日時 2020-03-23 19:48:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 3,413 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 134,984 KB
実行使用メモリ 85,920 KB
最終ジャッジ日時 2023-09-21 19:25:34
合計ジャッジ時間 8,512 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 149 ms
40,324 KB
testcase_06 AC 148 ms
40,420 KB
testcase_07 AC 148 ms
40,140 KB
testcase_08 AC 148 ms
40,512 KB
testcase_09 AC 147 ms
40,612 KB
testcase_10 AC 190 ms
85,920 KB
testcase_11 AC 82 ms
22,396 KB
testcase_12 AC 147 ms
40,352 KB
testcase_13 AC 68 ms
20,888 KB
testcase_14 AC 63 ms
20,160 KB
testcase_15 AC 76 ms
21,612 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 27 ms
10,660 KB
testcase_18 AC 123 ms
36,144 KB
testcase_19 AC 144 ms
39,712 KB
testcase_20 AC 52 ms
17,896 KB
testcase_21 AC 114 ms
34,312 KB
testcase_22 AC 86 ms
23,748 KB
testcase_23 AC 33 ms
11,952 KB
testcase_24 AC 34 ms
11,740 KB
testcase_25 AC 9 ms
5,160 KB
testcase_26 AC 112 ms
34,112 KB
testcase_27 AC 26 ms
10,676 KB
testcase_28 AC 28 ms
11,200 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 143 ms
39,572 KB
testcase_31 AC 115 ms
34,860 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 7 ms
4,376 KB
testcase_34 AC 67 ms
21,548 KB
testcase_35 AC 83 ms
22,104 KB
testcase_36 AC 63 ms
20,988 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 49 ms
13,180 KB
testcase_39 AC 27 ms
8,132 KB
testcase_40 AC 49 ms
12,940 KB
testcase_41 AC 37 ms
12,464 KB
testcase_42 AC 79 ms
22,116 KB
testcase_43 AC 6 ms
4,380 KB
testcase_44 AC 74 ms
21,648 KB
testcase_45 AC 43 ms
12,664 KB
testcase_46 AC 10 ms
5,356 KB
testcase_47 AC 24 ms
8,020 KB
testcase_48 AC 65 ms
20,984 KB
testcase_49 AC 4 ms
4,376 KB
testcase_50 AC 80 ms
21,992 KB
testcase_51 AC 44 ms
12,652 KB
testcase_52 AC 4 ms
4,376 KB
testcase_53 AC 144 ms
40,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


struct SegmentTree {

public:
	int n;
	vector<ll> node;
	vector<vector<pair<int, ll>>> g;
	SegmentTree(vector<ll> v) {
		int sz = v.size();
		n = 1; while (sz > n) n *= 2;
	}


	void add_edge(int a, int b, int nd, int len, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			g[nd + n - 1].emplace_back(k, len);
			return;
		}

		add_edge(a, b, nd, len, 2 * k + 1, l, (l + r) / 2);
		add_edge(a, b, nd, len, 2 * k + 2, (l + r) / 2, r);
	}
};

struct technique {
	ll a, b, c;
	int id;
	technique(ll _a, ll _b, ll _c, int _id) :a(_a), b(_b), c(_c), id(_id) {}
	bool operator <(technique &t) {
		if (a == t.a) {
			if (b == t.b) return c < t.c;
			else return b < t.b;
		}
		else return a < t.a;
	}
};

vector<ll> dp;
vector<bool> used;
vector<technique> vt;
vector<int> score;
int n;
ll dfs(int cur, SegmentTree& seg) {
	if (dp[cur] != -1) return dp[cur];
	if (used[cur]) return dp[cur] = INF;
	ll res = 0;
	used[cur] = true;
	for (auto next : seg.g[cur]) {
		ll tmp = dfs(next.first, seg);
		if (tmp == INF) res = INF;
		else chmax(res, tmp);
	}

	if (res == INF) return dp[cur] = INF;
	return dp[cur] = res + score[cur];
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%d", &n);

	vector<technique> vt; vt.reserve(n);
	for (int i = 0; i < n; i++) {
		ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
		vt.emplace_back(a, b, c, i);
	}
	SegmentTree seg(vector<ll>(n,0));
	n = seg.n;
	used = vector<bool>(n * 2, false);
	seg.g.resize(n * 2);
	dp = vector<ll>(n * 2, -1);
	score.resize(n * 2);
	for (int i = 0; i < n - 1; i++) {
		seg.g[i].emplace_back(i * 2 + 1, 0);
		seg.g[i].emplace_back(i * 2 + 2, 0);
	}
	sort(vt.begin(), vt.end());
	for (int i = 0; i < vt.size(); i++) {
		score[i + n - 1] = vt[i].b;
	}
	for (int i = 0; i < vt.size(); i++) {
		ll d = vt[i].b - vt[i].c;
		int left = -1;
		int right = vt.size();
		while (right - left > 1) {
			int mid = (left + right) >> 1;
			if (mid == vt.size()) left = mid;
			else if (d < vt[mid].a) right = mid;
			else left = mid;
		}
		//cout << i << " " << right << endl;
		if (right == 0) continue;
		if(right < i) seg.add_edge(0, right, i, 0);
		else {
			seg.add_edge(0, i, i, 0);
			if(i + 1!= right) seg.add_edge(i + 1, right, i, 0);
		}
	}
	vector<ll> ans(vt.size());
	for (int i = 0; i < vt.size(); i++) {
		ans[vt[i].id] = dfs(i + n - 1, seg);
	}
	for (int i = 0; i < ans.size(); i++) {
		if (ans[i] == INF) puts("BAN");
		else printf("%lld\n", ans[i]);
	}
	
	return 0;

}
0