제출 #414972

#제출 시각아이디문제언어결과실행 시간메모리
414972nvmdavaBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1626 ms420208 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 100005; const ll MOD = 1000000007; const ll INF = 0x3f3f3f3f3f3f3f3f; const int SQ = 300; vector<int> to[N], fr[N]; vector<pair<int, int> > ans[N]; int vis[N]; int tag = 0; int d[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin>>n>>m>>q; while(m--){ int s, e; cin>>s>>e; fr[s].push_back(e); to[e].push_back(s); } for(int i = 1; i <= n; ++i){ ans[i].push_back({i, 0}); for(auto& j : to[i]){ ++tag; vector<pair<int, int> > tmp, &v1 = ans[i], &v2 = ans[j]; int i1 = 0, i2 = 0, s1 = v1.size(), s2 = v2.size(); while(tmp.size() < SQ && (i1 < s1 || i2 < s2) ){ if(i1 != s1 && vis[v1[i1].ff] == tag){ ++i1; continue; } if(i2 != s2 && vis[v2[i2].ff] == tag){ ++i2; continue; } if(i2 == s2 || v1[i1].ss > v2[i2].ss + 1){ vis[v1[i1].ff] = tag; tmp.push_back({v1[i1].ff, v1[i1].ss}); ++i1; continue; } vis[v2[i2].ff] = tag; tmp.push_back({v2[i2].ff, v2[i2].ss + 1}); ++i2; } swap(v1, tmp); } } while(q--){ ++tag; int res = -1; int t, y; cin>>t>>y; while(y--){ int w; cin>>w; vis[w] = tag; } for(auto& [v, d] : ans[t]){ if(vis[v] != tag){ res = d; break; } } if(res != -1){ cout<<res<<'\n'; continue; } for(int i = t + 1; i <= n; ++i) d[i] = -MOD; d[t] = 0; if(vis[t] != tag) res = 0; for(int i = t - 1; i > 0; --i){ d[i] = -MOD; for(auto& x : fr[i]) d[i] = max(d[i], d[x] + 1); if(vis[i] != tag) res = max(res, d[i]); } cout<<res<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...