Submission #348371

#TimeUsernameProblemLanguageResultExecution timeMemory
348371AmShZBitaro’s Party (JOI18_bitaro)C++11
100 / 100
1492 ms386924 KiB
// khodaya khodet komak kon # include <bits/stdc++.h> /* // ordered_set # include <ext/pb_ds/assoc_container.hpp> # include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; # define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <pii, int> ppi; typedef pair <int, pii> pip; typedef pair <pii, pii> ppp; typedef pair <ll, ll> pll; # define A first # define B second # define endl '\n' # define sep ' ' # define all(x) x.begin(), x.end() # define kill(x) return cout << x << endl, 0 # define SZ(x) int(x.size()) # define lc id << 1 # define rc id << 1 | 1 # define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));} const int xn = 2e5 + 10; const int xm = - 20 + 10; const int sq = 450; const int inf = 1e9 + 10; const ll INF = 1e18 + 10; const int mod = 998244353; const int base = 257; int n, m, q, ptr[xn], dp[xn], ans[xn]; pii a[xn][sq], b[sq]; vector <int> adj[2][xn], vec[xn], query[xn]; bool mark[xn]; void solve(int id, int s){ memset(dp, - 1, sizeof dp); for (int v : vec[id]) mark[v] = true; dp[s] = 0; for (int v = s; v >= 1; -- v){ for (int u : adj[0][v]) if (dp[u] != - 1) dp[v] = max(dp[v], dp[u] + 1); if (!mark[v]) ans[id] = max(ans[id], dp[v]); } for (int v : vec[id]) mark[v] = false; } void merge(int v, int u){ int pt1 = 0, pt2 = 0, pt3 = 0; while (pt1 < ptr[v] || pt2 < ptr[u]){ if (pt3 == sq) break; if (pt1 < ptr[v] && mark[a[v][pt1].A]){ ++ pt1; continue; } if (pt2 < ptr[u] && mark[a[u][pt2].A]){ ++ pt2; continue; } if (pt2 == ptr[u] || (pt1 < ptr[v] && a[v][pt1].B >= a[u][pt2].B)) b[pt3 ++] = {a[v][pt1].A, a[v][pt1 ++].B + 1}; else b[pt3 ++] = a[u][pt2 ++]; mark[b[pt3 - 1].A] = true; } ptr[u] = pt3; for (int i = 0; i < pt3; ++ i) a[u][i] = b[i], mark[b[i].A] = false; } int main(){ InTheNameOfGod; cin >> n >> m >> q; while (m --){ int v, u; cin >> v >> u; adj[0][v].push_back(u); adj[1][u].push_back(v); } for (int i = 1; i <= q; ++ i){ int s, sz; cin >> s >> sz; ans[i] = - 1; for (int j = 0; j < sz; ++ j){ int v; cin >> v; vec[i].push_back(v); } if (sz >= sq) solve(i, s); else query[s].push_back(i); } memset(mark, false, sizeof mark); for (int v = 1; v <= n; ++ v){ for (int u : adj[1][v]) merge(u, v); if (ptr[v] < sq) a[v][ptr[v] ++] = {v, 0}; for (int id : query[v]){ for (int u : vec[id]) mark[u] = true; for (int i = ptr[v] - 1; i >= 0; -- i) if (!mark[a[v][i].A]) ans[id] = a[v][i].B; for (int u : vec[id]) mark[u] = false; } } for (int i = 1; i <= q; ++ i) cout << ans[i] << endl; return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'void merge(int, int)':
bitaro.cpp:77:39: warning: operation on 'pt1' may be undefined [-Wsequence-point]
   77 |    b[pt3 ++] = {a[v][pt1].A, a[v][pt1 ++].B + 1};
      |                                   ~~~~^~
bitaro.cpp:77:39: warning: operation on 'pt1' may be undefined [-Wsequence-point]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...