이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
I find it wholesome to be alone the greater part of the time.
To be in company, even with the best, is soon wearisome and dissipating.
I love to be alone.
I never found the companion that was so companionable as solitude.
*/
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 5e5 + 10;
//const int Mod = 1e9 + 7;
//const int inf =
int n;
vector <int> S[maxN];
int L[maxN], R[maxN];
int l[maxN], r[maxN];
int last[maxN];
int c[maxN];
bool inside(int l, int r, int x){
return l <= x && x <= r;
}
bool can(int l, int r, int x){
return inside(l, r, L[x]) || inside(l, r, R[x]);
}
void Init(){
cin >> n;
for (int i = 1; i < n; ++i) cin >> c[i];
for (int i = 1; i <= n; ++i){
int b; cin >> b;
while (b--){
int x; cin >> x;
S[i].pb(x);
}
}
for (int i = 2; i <= n; ++i){
for (int j: S[i - 1]){
last[j] = i - 1;
}
L[i] = last[c[i - 1]];
}
fill(last + 1, last + n + 1, n + 1);
R[n] = n + 1;
for (int i = n - 1; i >= 1; --i){
for (int j: S[i + 1]){
last[j] = i + 1;
}
R[i] = last[c[i]];
}
for (int i = 1; i <= n; ++i){
l[i] = r[i] = i;
while (1){
if (l[i] > 1 && can(l[i], r[i], l[i] - 1)){
r[i] = max(r[i], r[l[i] - 1]);
l[i] = l[l[i] - 1];
}
else{
if (r[i] < n && can(l[i], r[i], r[i] + 1))
++r[i];
else break;
}
}
}
int q; cin >> q;
while (q--){
int x, y;
cin >> x >> y;
cout << (inside(l[x], r[x], y) ? "YES\n" : "NO\n");
}
}
#define debug
#define taskname "test"
signed main(){
faster
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
int tt = 1;
//cin >> tt;
while (tt--){
Init();
}
if (fopen("timeout.txt", "r")){
ofstream timeout("timeout.txt");
timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
timeout.close();
#ifndef debug
cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
#endif // debug
}
}
컴파일 시 표준 에러 (stderr) 메시지
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
long_mansion.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
88 | freopen(taskname".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |