제출 #1096907

#제출 시각아이디문제언어결과실행 시간메모리
1096907dmitryAdams다리 (APIO19_bridges)C++17
29 / 100
416 ms4440 KiB
#ifdef NN_LOCALE #define _GLIBCXX_DEBUG #endif #include "iostream" #include "vector" #include "cstdint" using namespace std; struct edge { int v, u, d; }; vector<edge> e; vector<vector<int>> g; vector<int> used; int cnt = 0; void dfs(int v, int w, int clr) { used[v] = clr; ++cnt; for (auto ind : g[v]) { int d = e[ind].d; int u = e[ind].u ^ e[ind].v ^ v; if (d >= w && used[u] != clr) { dfs(u, w, clr); } } } vector<int> b; vector<int> tr; void build(int v, int l, int r) { if (r - l == 1) { tr[v] = b[l]; return; } int m = (r + l) / 2; build(2 * v + 1, l, m); build(2 * v + 2, m, r); tr[v] = min(tr[2 * v + 1], tr[2 * v + 2]); } void upd(int i, int x, int v, int l, int r) { if (r - l == 1) { tr[v] = x; return; } int m = (r + l) / 2; if (i < m) { upd(i, x, 2 * v + 1, l, m); } else { upd(i, x, 2 * v + 2, m, r); } tr[v] = min(tr[2 * v + 1], tr[2 * v + 2]); } int get(int ql, int qr, int v, int l, int r) { if (ql == qr) return -1; if (ql == l && qr == r) { return tr[v]; } int m = (r + l) / 2; if (qr <= m) { return get(ql, qr, 2 * v + 1, l, m); } else if (ql >= m) { return get(ql, qr, 2 * v + 2, m, r); } else { return min(get(ql, m, 2 * v + 1, l, m), get(m, qr, 2 * v + 2, m, r)); } } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); #ifdef NN_LOCALE freopen("in", "r", stdin); freopen("out", "w", stdout); #endif int n, m; cin >> n >> m; if (n <= 1000 && m <= 1000) { g.resize(n); used.resize(n); for (int i = 0; i < m; ++i) { int v, u, d; cin >> v >> u >> d; --v, --u; g[v].push_back(i); g[u].push_back(i); e.push_back({v, u, d}); } int q; cin >> q; int c = 0; while (q--) { int t; cin >> t; if (t == 1) { int bi, r; cin >> bi >> r; --bi; e[bi].d = r; } else { int s, w; cin >> s >> w; --s; cnt = 0; dfs(s, w, ++c); cout << cnt << '\n'; } } } else { b.resize(m); for (int i = 0; i < m; ++i) { int v; cin >> v >> v; cin >> b[i]; } int q; cin >> q; tr.resize(4 * m); build(0, 0, m); while (q--) { int t; cin >> t; if (t == 1) { int bi, r; cin >> bi >> r; --bi; upd(bi, r, 0, 0, m); } else { int s, w; cin >> s >> w; --s; int ans = 1; int l = 0, r = s + 1; while (r - l > 1) { int mid = (r + l) / 2; if (get(s - mid, s, 0, 0, m) >= w) { l = mid; } else { r = mid; } } ans += l; l = 0, r = n - s; while (r - l > 1) { int mid = (r + l) / 2; if (get(s, s + mid, 0, 0, m) >= w) { l = mid; } else { r = mid; } } ans += l; cout << ans << '\n'; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...