| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1292073 | qmdz1908 | Long Mansion (JOI17_long_mansion) | C++17 | 3095 ms | 17640 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pii pair <int, int>
#define fi first
#define se second
const int maxn = 5e5 + 5, oo = 1e18, mod = 1e9 + 7;
int n, c[maxn], L[maxn], R[maxn];
vector <int> a[maxn];
bool has (int l, int r, int x) {
return *lower_bound (a[x].begin(), a[x].end(), l) <= r;
}
void solve () {
cin >> n;
for (int i = 1; i < n; i++)
cin >> c[i];
for (int i = 1, m; i <= n; i++) {
cin >> m;
for (int j = 1, x; j <= m; j++) {
cin >> x;
a[x].push_back (i);
}
}
for (int i = 1; i <= n; i++) a[i].push_back (oo);
for (int i = 1; i <= n; i++) {
L[i] = R[i] = i;
bool loop = true;
while (loop) {
loop = false;
if (L[i] > 1 && has (L[i], R[i], c[L[i] - 1])) {
L[i] = min (L[i], L[L[i - 1]]);
R[i] = max (R[i], R[R[i - 1]]);
loop = true;
}
if (R[i] < n && has (L[i], R[i], c[R[i]])) {
R[i]++;
loop = true;
}
}
}
int q;
cin >> q;
while (q--) {
int x, y;
cin >> x >> y;
if (y >= L[x] && y <= R[x]) cout << "YES\n";
else cout << "NO\n";
}
}
signed main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen ("code.inp", "r")) {
freopen ("code.inp", "r", stdin);
freopen ("code.out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while (tc--) solve ();
}
컴파일 시 표준 에러 (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... | ||||
