Submission #314178

#TimeUsernameProblemLanguageResultExecution timeMemory
314178VROOM_VARUNLong Mansion (JOI17_long_mansion)C++14
100 / 100
311 ms54432 KiB
/* ID: varunra2 LANG: C++ TASK: mansion */ #include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "lib/debug.h" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define debug_arr(...) \ cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__) #pragma GCC diagnostic ignored "-Wsign-compare" //#pragma GCC diagnostic ignored "-Wunused-parameter" //#pragma GCC diagnostic ignored "-Wunused-variable" #else #define debug(...) 42 #endif #define EPS 1e-9 #define IN(A, B, C) assert(B <= A && A <= C) #define INF (int)1e9 #define MEM(a, b) memset(a, (b), sizeof(a)) #define MOD 1000000007 #define MP make_pair #define PB push_back #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define x first #define y second const double PI = acos(-1.0); typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef map<int, int> MPII; typedef multiset<int> MSETI; typedef set<int> SETI; typedef set<string> SETS; typedef vector<int> VI; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<string> VS; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto& a : x) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef vector<int> vi; #pragma GCC diagnostic ignored "-Wsign-compare" // util functions int main() { // #ifndef ONLINE_JUDGE // freopen("mansion.in", "r", stdin); // freopen("mansion.out", "w", stdout); // #endif cin.sync_with_stdio(0); cin.tie(0); int n; cin >> n; VI b(n); VI c(n); VVI gps(n); for (int i = 0; i < n - 1; i++) { cin >> c[i]; c[i]--; } for (int i = 0; i < n; i++) { cin >> b[i]; for (int j = 0; j < b[i]; j++) { int u; cin >> u; u--; gps[i].PB(u); } } VI bef(n), aft(n); VI lst(n, -1); for (int i = 0; i < n - 1; i++) { trav(x, gps[i]) { lst[x] = i; } bef[i] = lst[c[i]]; } lst.assign(n, n); for (int i = n - 1; i >= 1; i--) { trav(x, gps[i]) { lst[x] = i; } aft[i - 1] = lst[c[i - 1]]; } VI l(n), r(n); for (int i = 0; i < n; i++) { l[i] = i; r[i] = i; bool ok = true; while (ok) { ok = false; if (l[i] and aft[l[i] - 1] <= r[i]) { r[i] = max(r[i], r[l[i] - 1]); l[i] = l[l[i] - 1]; ok = true; } if (r[i] < n - 1 and bef[r[i]] >= l[i]) { r[i]++; ok = true; } } } int q; cin >> q; debug(l); debug(r); while (q--) { int x, y; cin >> x >> y; x--, y--; if (y <= r[x] and y >= l[x]) { cout << "YES\n"; } else { cout << "NO\n"; } } return 0; }

Compilation message (stderr)

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
long_mansion.cpp:124:3: note: in expansion of macro 'debug'
  124 |   debug(l);
      |   ^~~~~
long_mansion.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
long_mansion.cpp:125:3: note: in expansion of macro 'debug'
  125 |   debug(r);
      |   ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...