Submission #1287410

#TimeUsernameProblemLanguageResultExecution timeMemory
1287410limitsBitaro’s Party (JOI18_bitaro)C++20
100 / 100
723 ms157512 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define f0r(i, n) for (auto i = 0; i < (n); ++i)
#define fnr(i, n, k) for (auto i = (n); i < (k); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define F first
#define S second
#define ctn(x) cout << x << '\n'
#define forl(a, l) for (auto a : l)
#define ctl(l) for (auto &a : (l)) cout << a << ' '; cout << endl;
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define ub(v, x) (upper_bound(all(v), x) - begin(v))
#define pq priority_queue

template <class T>
using V = vector<T>;
using ll = long long;
using vi = V<int>;
using vl = V<ll>;
using pi = pair<int, int>;
using ti = tuple<int, int, int>;
using Adj = V<vi>;
using vvi = V<vi>;

const int S = 100;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, m, q;
	cin >> n >> m >> q;
	Adj G(n);
	int u, v;
	f0r(i, m) {
		cin >> u >> v;
		G[v-1].pb(u-1);
	}

	V<V<pi>> tops(n);
	vi from(n, -1);
	f0r(i, n) {
		tops[i].pb({0, i});
		vi frs;
		forl(v, G[i]) {
			for (auto &[d, u]: tops[v]) {
				if (d == -1) break;
				if (from[u] == -1) frs.pb(u);
				from[u] = max(from[u], d+1);
			}
		}
		forl(x, frs) {
			tops[i].pb({from[x], x});
			from[x] = -1;
		}
		sort(all(tops[i]), greater<pi>());
		while (tops[i].size() < S) tops[i].pb({-1, -1});
		tops[i].resize(S);
	}

	V<bool> block(n);
	f0r(i, q) {
		int t, y, x;
		cin >> t >> y;
		--t;
		if (y >= S) {
			vi mx(n);
			f0r(i, y) {
				cin >> x;
				mx[x-1] = -1e9;
			}
			for (int i = 0; i <= t; ++i) {
				forl(v, G[i]) mx[i] = max(mx[i], 1 + mx[v]);
			}
			ctn(max(mx[t], -1));
		} else {
			vi bs;
			f0r(i, y) {
				cin >> x;
				bs.pb(--x);
				block[x] = 1;
			}
			for (auto &[d, u]: tops[t]) {
				if (u == -1 || !block[u]) {
					ctn(d);
					break;
				}
			}
			forl(x, bs) block[x] = 0;
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...