結果

問題 No.1014 competitive fighting
ユーザー chocoruskchocorusk
提出日時 2020-03-20 22:37:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 312 ms / 2,000 ms
コード長 2,871 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 132,260 KB
実行使用メモリ 112,576 KB
最終ジャッジ日時 2023-09-21 19:19:56
合計ジャッジ時間 11,768 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,652 KB
testcase_01 AC 3 ms
7,532 KB
testcase_02 AC 3 ms
6,668 KB
testcase_03 AC 2 ms
6,736 KB
testcase_04 AC 3 ms
7,700 KB
testcase_05 AC 304 ms
86,700 KB
testcase_06 AC 301 ms
86,660 KB
testcase_07 AC 299 ms
86,616 KB
testcase_08 AC 307 ms
86,428 KB
testcase_09 AC 304 ms
86,548 KB
testcase_10 AC 264 ms
112,576 KB
testcase_11 AC 175 ms
82,656 KB
testcase_12 AC 298 ms
86,604 KB
testcase_13 AC 134 ms
45,624 KB
testcase_14 AC 126 ms
44,848 KB
testcase_15 AC 142 ms
46,720 KB
testcase_16 AC 9 ms
10,140 KB
testcase_17 AC 54 ms
24,952 KB
testcase_18 AC 257 ms
81,512 KB
testcase_19 AC 301 ms
85,856 KB
testcase_20 AC 108 ms
42,176 KB
testcase_21 AC 246 ms
79,028 KB
testcase_22 AC 170 ms
49,788 KB
testcase_23 AC 66 ms
26,744 KB
testcase_24 AC 68 ms
27,216 KB
testcase_25 AC 17 ms
12,244 KB
testcase_26 AC 245 ms
79,080 KB
testcase_27 AC 55 ms
24,372 KB
testcase_28 AC 61 ms
24,832 KB
testcase_29 AC 5 ms
7,940 KB
testcase_30 AC 308 ms
85,660 KB
testcase_31 AC 244 ms
80,020 KB
testcase_32 AC 4 ms
7,624 KB
testcase_33 AC 14 ms
12,292 KB
testcase_34 AC 153 ms
75,848 KB
testcase_35 AC 179 ms
81,776 KB
testcase_36 AC 148 ms
74,640 KB
testcase_37 AC 9 ms
8,916 KB
testcase_38 AC 103 ms
47,552 KB
testcase_39 AC 55 ms
26,768 KB
testcase_40 AC 102 ms
47,184 KB
testcase_41 AC 84 ms
42,472 KB
testcase_42 AC 175 ms
81,308 KB
testcase_43 AC 14 ms
11,128 KB
testcase_44 AC 167 ms
79,104 KB
testcase_45 AC 92 ms
45,200 KB
testcase_46 AC 23 ms
14,768 KB
testcase_47 AC 52 ms
26,412 KB
testcase_48 AC 153 ms
75,468 KB
testcase_49 AC 9 ms
9,408 KB
testcase_50 AC 173 ms
80,000 KB
testcase_51 AC 94 ms
45,560 KB
testcase_52 AC 9 ms
8,764 KB
testcase_53 AC 312 ms
86,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
struct SCC{
    vector<vector<int>> g, gr;
    int n, k;
    vector<int> cmp, vs;
    vector<bool> used;
    void dfs(int x){
        used[x]=1;
        for(auto y:g[x]){
            if(!used[y]) dfs(y);
        }
        vs.push_back(x);
    }
    void rdfs(int v, int k){
        used[v]=1;
        cmp[v]=k;
        for(auto y:gr[v]){
            if(!used[y]) rdfs(y, k);
        }
    }
    SCC(const vector<vector<int>> &g):g(g), n(g.size()), cmp(n), used(n){
        gr.resize(n);
        for(int x=0; x<n; x++) for(auto y:g[x]) gr[y].push_back(x);
        for(int i=0; i<n; i++){
            if(!used[i]) dfs(i);
        }
        fill(used.begin(), used.end(), 0);
        k=0;
        for(int i=vs.size()-1; i>=0; i--){
            if(!used[vs[i]]) rdfs(vs[i], k++);
        }
    }
};
int main()
{
	int n;
	scanf("%d", &n);
	int a[100010], b[100010], c[100010];
	vector<P> v(n);
	for(int i=0; i<n; i++){
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
		v[i]=P(a[i], i);
	}
	sort(v.begin(), v.end());
	int sz=1;
	while(sz<n) sz<<=1;
	vector<vector<int>> g(2*sz+n);
	for(int i=1; i<sz; i++){
		g[i].push_back(i<<1);
		g[i].push_back((i<<1)^1);
	}
	for(int i=0; i<n; i++){
		g[i+sz].push_back(2*sz+i);
	}
	auto add_edge=[&](int a, int b, int k){
		if(a>=b || a>=n) return;
		a+=sz, b+=sz;
		for(;a<b; a>>=1, b>>=1){
			if(b&1){
				g[k+2*sz].push_back(--b);
			}
			if(a&1){
				g[k+2*sz].push_back(a++);
			}
		}
	};
	int l[100010];
	for(int i=0; i<n; i++){
		int k=v[i].second;
		l[i]=lower_bound(v.begin(), v.end(), P(b[k]-c[k], n))-v.begin();
		if(l[i]<=i){
			add_edge(0, l[i], i);
		}else{
			add_edge(0, i, i);
			add_edge(i+1, l[i], i);
		}
	}
	const ll INF=1e18;
	ll dp[400000]={};
	SCC scc(g);
	int k=scc.k;
	vector<vector<P>> dag(k);
	for(int i=0; i<2*sz+n; i++){
		for(auto y:g[i]){
			int s=scc.cmp[i], t=scc.cmp[y];
			if(s==t) dp[s]=INF;
			else if(sz<=i && i<sz+n && y==i+sz){
				int j=v[i-sz].second;
				dag[t].push_back({s, b[j]});
			}else{
				dag[t].push_back({s, 0});
			}
		}
	}
	for(int i=k-1; i>=0; i--){
		for(auto pr:dag[i]){
			int y=pr.first;
			dp[y]=max(dp[y], dp[i]+pr.second);
		}
	}
	ll ans[100010];
	for(int i=0; i<n; i++){
		int j=v[i].second;
		ans[j]=dp[scc.cmp[2*sz+i]]+b[j];
	}
	for(int i=0; i<n; i++){
		if(ans[i]>=INF) printf("BAN\n");
		else printf("%lld\n", ans[i]);
	}
	return 0;
}
0