Submission #1266599

#TimeUsernameProblemLanguageResultExecution timeMemory
1266599quangminh412Long Mansion (JOI17_long_mansion)C++17
100 / 100
210 ms38252 KiB
/* Ben Watson Quang Minh MasterDDDDD */ #include <bits/stdc++.h> using namespace std; #define ll long long const string name = "test"; void solve(); signed main() { if (fopen((name + ".inp").c_str(), "r")) { freopen((name + ".inp").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } // main program const int oo = 0x3f3f3f3f; const int maxn = 5e5 + 1; vector<int> keys[maxn]; int c[maxn], L[maxn], R[maxn]; int n, q; bool include(int l, int r, int x) { auto it = lower_bound(keys[x].begin(), keys[x].end(), l); return ((*it) <= r); } void solve() { cin >> n; for (int i = 1; i < n; i++) cin >> c[i]; for (int i = 1; i <= n; i++) { int b; cin >> b; for (int j = 0; j < b; j++) { int a; cin >> a; keys[a].push_back(i); } } for (int i = 1; i <= n; i++) keys[i].push_back(oo); for (int i = 1; i <= n; i++) { L[i] = R[i] = i; bool loop = 1; while (loop) { loop = 0; if (L[i] != 1 && include(L[i], R[i], c[L[i] - 1])) { R[i] = max(R[i], R[L[i] - 1]); L[i] = min(L[i], L[L[i] - 1]); loop = 1; } if (R[i] != n && include(L[i], R[i], c[R[i]])) { R[i]++; loop = 1; } } } cin >> q; while (q--) { int x, y; cin >> x >> y; cout << (L[x] <= y && y <= R[x] ? "YES\n" : "NO\n"); } }

Compilation message (stderr)

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((name + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...