# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1266585 | quangminh412 | Long Mansion (JOI17_long_mansion) | C++17 | 2343 ms | 17256 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 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);
if (it == keys[x].end())
return false;
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++)
{
L[i] = R[i] = i;
while (1)
{
if (L[i] != 1 && include(L[i], R[i], c[L[i] - 1]))
{
L[i] = min(L[i], L[L[i] - 1]);
R[i] = max(R[i], R[L[i] - 1]);
continue;
}
if (R[i] != n && include(L[i], R[i], c[R[i]]))
{
R[i]++;
continue;
}
break;
}
}
cin >> q;
while (q--)
{
int x, y; cin >> x >> y;
cout << (L[x] <= y && y <= R[x] ? "YES\n" : "NO\n");
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |