結果
問題 | No.1014 competitive fighting |
ユーザー | heno239 |
提出日時 | 2020-04-07 14:49:58 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 263 ms / 2,000 ms |
コード長 | 6,130 bytes |
コンパイル時間 | 1,812 ms |
コンパイル使用メモリ | 144,568 KB |
実行使用メモリ | 92,644 KB |
最終ジャッジ日時 | 2024-07-07 13:12:43 |
合計ジャッジ時間 | 11,024 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
7,496 KB |
testcase_01 | AC | 4 ms
7,552 KB |
testcase_02 | AC | 4 ms
7,424 KB |
testcase_03 | AC | 3 ms
7,496 KB |
testcase_04 | AC | 3 ms
7,624 KB |
testcase_05 | AC | 243 ms
68,180 KB |
testcase_06 | AC | 252 ms
68,036 KB |
testcase_07 | AC | 241 ms
68,076 KB |
testcase_08 | AC | 239 ms
68,132 KB |
testcase_09 | AC | 248 ms
67,884 KB |
testcase_10 | AC | 263 ms
92,644 KB |
testcase_11 | AC | 187 ms
64,924 KB |
testcase_12 | AC | 250 ms
68,120 KB |
testcase_13 | AC | 110 ms
37,196 KB |
testcase_14 | AC | 102 ms
36,900 KB |
testcase_15 | AC | 113 ms
37,728 KB |
testcase_16 | AC | 9 ms
9,156 KB |
testcase_17 | AC | 48 ms
21,736 KB |
testcase_18 | AC | 222 ms
66,664 KB |
testcase_19 | AC | 249 ms
67,816 KB |
testcase_20 | AC | 96 ms
36,232 KB |
testcase_21 | AC | 212 ms
65,896 KB |
testcase_22 | AC | 124 ms
38,436 KB |
testcase_23 | AC | 53 ms
22,244 KB |
testcase_24 | AC | 54 ms
22,248 KB |
testcase_25 | AC | 15 ms
11,008 KB |
testcase_26 | AC | 206 ms
65,768 KB |
testcase_27 | AC | 48 ms
21,736 KB |
testcase_28 | AC | 49 ms
22,120 KB |
testcase_29 | AC | 6 ms
7,884 KB |
testcase_30 | AC | 241 ms
67,684 KB |
testcase_31 | AC | 217 ms
66,044 KB |
testcase_32 | AC | 6 ms
8,064 KB |
testcase_33 | AC | 14 ms
10,880 KB |
testcase_34 | AC | 161 ms
63,692 KB |
testcase_35 | AC | 169 ms
64,584 KB |
testcase_36 | AC | 158 ms
63,268 KB |
testcase_37 | AC | 9 ms
9,088 KB |
testcase_38 | AC | 94 ms
36,456 KB |
testcase_39 | AC | 48 ms
21,864 KB |
testcase_40 | AC | 93 ms
36,360 KB |
testcase_41 | AC | 83 ms
35,804 KB |
testcase_42 | AC | 170 ms
64,560 KB |
testcase_43 | AC | 13 ms
10,880 KB |
testcase_44 | AC | 165 ms
64,132 KB |
testcase_45 | AC | 89 ms
36,056 KB |
testcase_46 | AC | 22 ms
14,336 KB |
testcase_47 | AC | 47 ms
21,736 KB |
testcase_48 | AC | 154 ms
63,464 KB |
testcase_49 | AC | 8 ms
9,164 KB |
testcase_50 | AC | 167 ms
64,364 KB |
testcase_51 | AC | 88 ms
36,244 KB |
testcase_52 | AC | 9 ms
9,088 KB |
testcase_53 | AC | 242 ms
67,944 KB |
コンパイルメッセージ
main.cpp: In member function 'std::vector<long long int> graph::query(std::vector<long long int>, int)': main.cpp:211:44: warning: 'ss' may be used uninitialized [-Wmaybe-uninitialized] 211 | memo[i] += ss; | ^~ main.cpp:194:39: note: 'ss' was declared here 194 | int u,ss; | ^~ main.cpp:212:38: warning: 'u' may be used uninitialized [-Wmaybe-uninitialized] 212 | res[u] = memo[i]; | ^ main.cpp:194:37: note: 'u' was declared here 194 | int u,ss; | ^
ソースコード
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> #include<complex> #include<numeric> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; ll mod = 1000000007; const ll INF = mod * mod; typedef pair<int, int>P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acos(-1.0); ll mod_pow(ll a, ll n, ll m = mod) { ll res = 1; while (n) { if (n & 1)res = res * a%m; a = a * a%m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n%mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, int n) { if (n == 0)return modint(1); modint res = (a*a) ^ (n / 2); if (n % 2)res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 1 << 18; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } int dx[4] = { 0,1,0,-1 }; int dy[4] = { 1,0,-1,0 }; struct graph { private: int n; vector<vector<int>> G, rG; vector<bool> used; vector<int> vs; int mk; vector<vector<int>> fG; vector<vector<int>> ori; vector<int> trans; public: graph(int sz) { n = sz; G.resize(n); rG.resize(n); used.resize(n); fG.resize(n); trans.resize(n, -1); ori.resize(n); } void add_edge(int a, int b) { G[a].push_back(b); rG[b].push_back(a); } void dfs(int v) { used[v] = true; rep(i, G[v].size()) { if (!used[G[v][i]])dfs(G[v][i]); } vs.push_back(v); } void rdfs(int v, int k) { used[v] = true; queue<int> q; q.push(v); vector<int> c; while (!q.empty()) { int id = q.front(); q.pop(); ori[k].push_back(id); rep(j, rG[id].size()) { int to = rG[id][j]; if (used[to]) { if (trans[to] >= 0)c.push_back(trans[to]); continue; } used[to] = true; q.push(to); } } sort(c.begin(), c.end()); int len = unique(c.begin(), c.end()) - c.begin(); rep(i, len) { fG[c[i]].push_back(k); } rep(i, ori[k].size()) { trans[ori[k][i]] = k; } } void scc() { fill(used.begin(), used.end(), false); rep(i, n) { if (!used[i])dfs(i); } fill(used.begin(), used.end(), false); int k = 0; per(i, (int)vs.size()) { if (!used[vs[i]]) { rdfs(vs[i], k); k++; } } mk = k; } vector<ll> query(vector<ll> c, int bef) { vector<ll> res(c.size()); vector<ll> memo(mk); int sz = c.size(); per(i, mk) { int cnt = 0; rep(j, ori[i].size()) { if (ori[i][j] >= bef - 1 && ori[i][j]<bef - 1 + sz) { cnt++; } } if (cnt >= 2) { memo[i] = INF; for (int id : ori[i]) { int tid = id - (bef - 1); if (tid >= 0 && tid < sz) { res[tid] = INF; } } } else if (cnt == 1) { int u,ss; for (int id : ori[i]) { int tid = id - (bef - 1); if (tid >= 0 && tid < sz) { u = tid; ss = c[tid]; } } memo[i] = 0; for (int to : fG[i]) { if (memo[to] == INF) { memo[i] = INF; break; } else { memo[i] = max(memo[i], memo[to]); } } memo[i] += ss; res[u] = memo[i]; } else { for (int to : fG[i]) { memo[i] = max(memo[i], memo[to]); } } } return res; } }; int sz; void add_seg(graph &g, int &fr, int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0)r = sz; if (r <= a || b <= l)return; else if (a <= l && r <= b) { g.add_edge(fr, k); } else { add_seg(g, fr, a, b, k * 2 + 1, l, (l + r) / 2); add_seg(g, fr, a, b, k * 2 + 2, (l + r) / 2, r); } } void solve() { int n; cin >> n; vector<pair<P,P>> v; rep(i, n) { int a, b, c; cin >> a >> b >> c; v.push_back({ {a,b - c},{b,i} }); } vector<ll> cs(n); sort(all(v)); rep(i, n)cs[i] = v[i].second.first; vector<int> x; rep(i, n)x.push_back(v[i].first.first); sz = 1; while (sz < n)sz *= 2; graph g(2 * sz - 1); rep(i, sz - 1) { g.add_edge(i, 2 * i + 1); g.add_edge(i, 2 * i + 2); } rep(i, n) { int id = upper_bound(all(x), v[i].first.second) - x.begin(); int fr = i + sz - 1; if (id <= i) { add_seg(g, fr, 0, id); } else { add_seg(g, fr, 0, i); add_seg(g, fr, i + 1, id); } } g.scc(); vector<ll> fans = g.query(cs, sz); vector<ll> ans(n); rep(i, n) { ans[v[i].second.second] = fans[i]; } rep(i, n) { if (ans[i] >= INF)cout << "BAN\n"; else cout << ans[i] << "\n"; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(7); //init_f(); //init(); //int t; cin >> t; rep(i, t)solve(); solve(); stop return 0; }