Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#pragma GCC optimize("Ofast,unroll-loops")
- #ifdef LOCAL
- #include "debug.h"
- #else
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define debug(x...)
- #endif
- using namespace std;
- #define int ll
- typedef long long ll;
- typedef long double ld;
- typedef pair <int, int> pii;
- #define sz(x) int((x).size())
- template <typename T>
- using ordered_set = __gnu_pbds::tree <T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
- #ifdef ONLINE_JUDGE
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- #else
- mt19937 rng(1000 - 7);
- #endif
- const int N = 1e5 + 10;
- //const int MOD = 998244353;
- const ll MOD = 1e9 + 9;
- const ld eps = 5e-8;
- const pii dir[] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };
- ll val[N], k[N], b[N];
- char used[N];
- int n, m, type[N];
- vector <int> g[N];
- void dfs(int u) {
- used[u] = 1;
- for (int v : g[u]) {
- if (!used[v]) {
- dfs(v);
- }
- if (type[u] == 1) {
- k[u] = (k[u] + k[v]) % MOD;
- b[u] = (b[u] + b[v]) % MOD;
- }
- if (type[u] == 2) {
- if (k[v]) {
- assert(k[u] == 0);
- k[u] = k[v];
- b[u] = b[v];
- }
- }
- }
- if (type[u] == 2) {
- if (!k[u]) {
- b[u] = 1;
- for (int v : g[u]) {
- b[u] = (b[u] * b[v]) % MOD;
- }
- }
- else {
- for (int v : g[u]) {
- if (!k[v]) {
- k[u] = (k[u] * b[v]) % MOD;
- b[u] = (b[u] * b[v]) % MOD;
- }
- debug(k[v], b[v]);
- }
- }
- }
- if (type[u] == 3) {
- k[u] = 1;
- b[u] = 0;
- assert(g[u].empty());
- }
- if (type[u] == 4) {
- k[u] = 0;
- b[u] = val[u];
- assert(g[u].empty());
- }
- }
- signed main() {
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- cout << fixed << setprecision(9);
- ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
- int q;
- cin >> n >> m >> q;
- for (int i = 0; i < n; i++) {
- string s;
- cin >> s;
- if (s == "+") {
- type[i] = 1;
- }
- else if (s == "*") {
- type[i] = 2;
- }
- else if (s == "x") {
- type[i] = 3;
- }
- else {
- type[i] = 4;
- val[i] = stoi(s);
- }
- }
- for (int i = 0; i < m; i++) {
- int u, v;
- cin >> u >> v;
- g[v - 1].push_back(u - 1);
- }
- dfs(0);
- for (int i = 0; i < n; i++) {
- debug(i + 1, k[i], b[i]);
- }
- while (q--) {
- ll x;
- cin >> x;
- cout << (k[0] * x + b[0]) % MOD << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement