Submission #1151576

#TimeUsernameProblemLanguageResultExecution timeMemory
1151576The_SamuraiFile Paths (BOI15_fil)C++20
100 / 100
545 ms121128 KiB
// I stand with PALESTINE //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("avx,avx2") #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> using namespace std; //using namespace __gnu_pbds; // #define int long long #define ff first #define ss second #define sz(a) (int) (a).size() //template<class T, class C = null_type> using ordered_tree = tree<T, C, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long double ld; namespace io { template<typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << p.ff << " " << p.ss; } template<typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &mp) { for (auto it: mp) { os << it << endl; } return os; } template<typename F> ostream &operator<<(ostream &os, const vector<F> &v) { bool space = false; for (F x: v) { if (space) os << " "; space = true; os << x; } return os; } template<typename F> ostream &operator<<(ostream &os, const deque<F> &d) { bool space = false; for (F x: d) { if (space) os << " "; space = true; os << x; } return os; } template<typename F> ostream &operator<<(ostream &os, const set<F> &st) { bool space = false; for (F x: st) { if (space) os << " "; space = true; os << x; } return os; } template<typename F> ostream &operator<<(ostream &os, const multiset<F> &st) { bool space = false; for (F x: st) { if (space) os << " "; space = true; os << x << x; } return os; } template<typename F, typename S> istream &operator>>(istream &is, pair<F, S> &p) { return is >> p.ff >> p.ss; } template<typename F> istream &operator>>(istream &is, vector<F> &v) { for (F &x: v) { is >> x; } return is; } long long fastread() { char c; long long d = 1, x = 0; do c = getchar(); while (c == ' ' || c == '\n'); if (c == '-') c = getchar(), d = -1; while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return d * x; } static bool sep = false; using std::to_string; string to_string(bool x) { return (x ? "true" : "false"); } string to_string(const string &s) { return "\"" + s + "\""; } string to_string(const char *s) { return "\"" + string(s) + "\""; } string to_string(const char &c) { string s; s += c; return "\'" + s + "\'"; } template<typename Type> string to_string(vector<Type>); template<typename F, typename S> string to_string(pair<F, S>); template<typename Collection> string to_string(Collection); template<typename F, typename S> string to_string(pair<F, S> p) { return "{" + to_string(p.ff) + ", " + to_string(p.ss) + "}"; } template<typename Type> string to_string(vector<Type> v) { bool sep = false; string s = "["; for (Type x: v) { if (sep) s += ", "; sep = true; s += to_string(x); } s += "]"; return s; } template<typename Collection> string to_string(Collection collection) { bool sep = false; string s = "{"; for (auto x: collection) { if (sep) s += ", "; sep = true; s += to_string(x); } s += "}"; return s; } void print() { cout << endl; sep = false; } template<typename F, typename... Other> void print(F ff, Other... other) { if (sep) cout << " | "; sep = true; cout << to_string(ff); print(other...); } } using namespace io; namespace utils { template<typename F, typename S> inline void maxs(F &a, S b) { a = a > b ? a : b; } template<typename F, typename S> inline void mins(F &a, S b) { a = a < b ? a : b; } template<typename F, typename S> long long max(F a, S b) { return a > b ? a : b; } template<typename F, typename S> long long min(F a, S b) { return a < b ? a : b; } constexpr long long operator "" _E(unsigned long long n) { long long p = 1, a = 10; for (int i = 0; i < n; i++) p *= a; return p; } random_device rd; mt19937 mt(rd()); template<typename T> T rand(T l, T r) { uniform_int_distribution<T> dist(l, r); return dist(mt); }; } using namespace utils; #ifdef sunnatov #define print(...) cout << "[" << #__VA_ARGS__ << "]: "; io::print( __VA_ARGS__ ); #else #define print( ... ) 42 #endif const int mod = 9_E + 7; const double EPS = 1e-7; long long doxuya = 18_E + 10; int INF = 9_E + 10; const char nl = '\n'; int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; /* fixing the path that symlink goes? intrsting */ const int N = 1e6 + 5; void solution(istream &cin, ostream &cout, const int &test_case) { vector<basic_string<int>> div(N); for (int i = 1; i < N; i++) for (int j = i; j < N; j += i) { div[j].push_back(i); } int n, m, k, s; cin >> n >> m >> k >> s; vector<vector<int>> g(n + m + 1); vector<int> l(n + m + 1), p(n + m + 1); for (int i = 1; i <= n + m; i++) cin >> p[i] >> l[i]; for (int i = 0; i <= n; i++) l[i]++; for (int i = 1; i <= n + m; i++) g[p[i]].emplace_back(i); for (int i = 1; i <= n + m; i++) assert(p[i] <= 1e9); const int lg = 13; vector jump(lg, vector(n + m + 1, 0)); vector<int> tin(n + m + 1), tout(n + m + 1), depth(n + m + 1); int z = 0; auto dfs = [&](auto &dfs, int u) -> void { depth[u] = l[u] + (u > 0 ? depth[p[u]] : 0); jump[0][u] = p[u]; for (int i = 1; i < lg and u > 0; i++) { jump[i][u] = jump[i - 1][jump[i - 1][u]]; if (!jump[i][u]) break; } tin[u] = z++; for (int v: g[u]) dfs(dfs, v); tout[u] = z++; }; dfs(dfs, 0); auto isPar = [&](int u, int v) -> bool { return tin[u] <= tin[v] and tout[v] <= tout[u]; }; auto lca = [&](int u, int v) -> int { if (isPar(u, v)) return u; if (isPar(v, u)) return v; for (int i = lg - 1; i >= 0; i--) { if (jump[i][u] and !isPar(jump[i][u], v)) u = jump[i][u]; } return jump[0][u]; }; vector<bool> ex(N), ans(n + m + 1); for (int root = 0; root <= n; root++) { // path shu yerga qaytadi // depth[root] + (depth[sys] - depth[root]) * x + (depth[u] - depth[root]) == k for (int sys = root; sys <= n; sys++) { if (isPar(root, sys) and depth[sys] - depth[root] + s + 1 <= k) { ex[depth[sys] - depth[root] + s + 1] = true; } } for (int u = n + 1; u <= n + m; u++) { if (!isPar(root, u) or ans[u]) continue; int need = k - depth[root] - (depth[u] - depth[root]); for (int val: div[need]) ans[u] = ans[u] | ex[val]; // if (ans[u]) { // cout << root << ' ' << u << ' ' << need << ' ' << depth[u] << endl; // } } for (int sys = root; sys <= n; sys++) { if (isPar(root, sys) and depth[sys] - depth[root] + s + 1 <= k) { ex[depth[sys] - depth[root] + s + 1] = false; } } } for (int u = n + 1; u <= n + m; u++) { if (depth[u] == k) ans[u] = true; if (!ans[u]) { int pp = p[u]; while (true) { if (depth[u] - depth[pp] <= k) ex[depth[u] - depth[pp]] = true; if (!pp) break; pp = p[pp]; } for (int v = 0; v <= n and !ans[u]; v++) { int sum = depth[v] + s + 1; if (k - sum >= 0) ans[u] = ex[k - sum]; } pp = p[u]; while (true) { if (depth[u] - depth[pp] <= k) ex[depth[u] - depth[pp]] = false; if (!pp) break; pp = p[pp]; } } cout << (ans[u] ? "YES\n" : "NO\n"); } } int32_t main() { clock_t startTime = clock(); cin.tie(0)->sync_with_stdio(false); srand(time(0)); std::istream &in(std::cin); std::ostream &out(std::cout); int32_t queries = 1; #ifdef sunnatov freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); // cin >> queries; #else // cin >> queries; #endif for (int32_t test_case = 1; test_case <= queries; test_case++) { print(test_case); solution(cin, cout, test_case); // cout << nl; } #ifdef sunnatov cout << "Time: " << (int) ((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl; #endif return EXIT_SUCCESS; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...