# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
125289 | 2019-07-05T04:48:43 Z | 구재현(#3066) | Long Mansion (JOI17_long_mansion) | C++14 | 145 ms | 16120 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 500005; using lint = long long; using pi = pair<int, int>; int n, c[MAXN]; vector<int> key_loc[MAXN]; int L[MAXN], R[MAXN]; int up[MAXN], dn[MAXN]; pi rng[MAXN]; int main(){ scanf("%d",&n); if(n > 10000) return 0; for(int i=1; i<n; i++) scanf("%d",&c[i]); for(int i=1; i<=n; i++){ int x; scanf("%d",&x); for(int j=0; j<x; j++){ int y; scanf("%d",&y); key_loc[y].push_back(i); } } for(int i=1; i<n; i++){ auto p = lower_bound(key_loc[c[i]].begin(), key_loc[c[i]].end(), i + 1); if(p == key_loc[c[i]].end()) R[i] = n + 1; else R[i] = *p; if(p == key_loc[c[i]].begin()) L[i] = 0; else L[i] = *prev(p); } R[0] = n + 1; L[n + 1] = 0; memset(dn, 0x3f, sizeof(dn)); for(int i=1; i<=n; i++){ for(int j=i; j<R[i-1]; j++){ if(L[j] < i){ up[i] = max(up[i], j); } } } for(int i=1; i<=n; i++){ for(int j=L[i] + 1; j<=i; j++){ if(R[j - 1] > i){ dn[i] = min(dn[i], j); } } } vector<pi> stk; for(int i=1; i<=n; i++){ while(!stk.empty() && stk.back().first <= max(i - 1, up[i])){ stk.pop_back(); } if(up[i] >= i) stk.emplace_back(up[i], i); if(stk.size()) rng[i].first = stk.back().second; else rng[i].first = 1; } stk.clear(); for(int i=n; i; i--){ while(!stk.empty() && stk.back().first >= min(i + 1, dn[i])){ stk.pop_back(); } if(dn[i] <= i) stk.emplace_back(dn[i], i); if(stk.size()) rng[i].second = stk.back().second; else rng[i].second = n; } int q; scanf("%d",&q); while(q--){ int x, y; scanf("%d %d",&x,&y); puts(rng[x].first <= y && y <= rng[x].second ? "YES" : "NO"); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 14072 KB | Output is correct |
2 | Correct | 17 ms | 14200 KB | Output is correct |
3 | Correct | 18 ms | 14204 KB | Output is correct |
4 | Correct | 17 ms | 14200 KB | Output is correct |
5 | Correct | 16 ms | 14200 KB | Output is correct |
6 | Correct | 17 ms | 14200 KB | Output is correct |
7 | Correct | 22 ms | 14200 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 14072 KB | Output is correct |
2 | Correct | 17 ms | 14200 KB | Output is correct |
3 | Correct | 18 ms | 14204 KB | Output is correct |
4 | Correct | 17 ms | 14200 KB | Output is correct |
5 | Correct | 16 ms | 14200 KB | Output is correct |
6 | Correct | 17 ms | 14200 KB | Output is correct |
7 | Correct | 22 ms | 14200 KB | Output is correct |
8 | Correct | 142 ms | 15692 KB | Output is correct |
9 | Correct | 142 ms | 15608 KB | Output is correct |
10 | Correct | 145 ms | 15872 KB | Output is correct |
11 | Correct | 143 ms | 15976 KB | Output is correct |
12 | Correct | 134 ms | 15864 KB | Output is correct |
13 | Correct | 140 ms | 15840 KB | Output is correct |
14 | Correct | 139 ms | 15824 KB | Output is correct |
15 | Correct | 138 ms | 15980 KB | Output is correct |
16 | Correct | 132 ms | 16120 KB | Output is correct |
17 | Correct | 139 ms | 15864 KB | Output is correct |
18 | Correct | 140 ms | 15836 KB | Output is correct |
19 | Correct | 137 ms | 15908 KB | Output is correct |
20 | Correct | 134 ms | 16120 KB | Output is correct |
21 | Correct | 131 ms | 16052 KB | Output is correct |
22 | Correct | 137 ms | 15936 KB | Output is correct |
23 | Correct | 144 ms | 15740 KB | Output is correct |
24 | Correct | 144 ms | 15736 KB | Output is correct |
25 | Correct | 144 ms | 15736 KB | Output is correct |
26 | Correct | 145 ms | 15760 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 12024 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 14072 KB | Output is correct |
2 | Correct | 17 ms | 14200 KB | Output is correct |
3 | Correct | 18 ms | 14204 KB | Output is correct |
4 | Correct | 17 ms | 14200 KB | Output is correct |
5 | Correct | 16 ms | 14200 KB | Output is correct |
6 | Correct | 17 ms | 14200 KB | Output is correct |
7 | Correct | 22 ms | 14200 KB | Output is correct |
8 | Correct | 142 ms | 15692 KB | Output is correct |
9 | Correct | 142 ms | 15608 KB | Output is correct |
10 | Correct | 145 ms | 15872 KB | Output is correct |
11 | Correct | 143 ms | 15976 KB | Output is correct |
12 | Correct | 134 ms | 15864 KB | Output is correct |
13 | Correct | 140 ms | 15840 KB | Output is correct |
14 | Correct | 139 ms | 15824 KB | Output is correct |
15 | Correct | 138 ms | 15980 KB | Output is correct |
16 | Correct | 132 ms | 16120 KB | Output is correct |
17 | Correct | 139 ms | 15864 KB | Output is correct |
18 | Correct | 140 ms | 15836 KB | Output is correct |
19 | Correct | 137 ms | 15908 KB | Output is correct |
20 | Correct | 134 ms | 16120 KB | Output is correct |
21 | Correct | 131 ms | 16052 KB | Output is correct |
22 | Correct | 137 ms | 15936 KB | Output is correct |
23 | Correct | 144 ms | 15740 KB | Output is correct |
24 | Correct | 144 ms | 15736 KB | Output is correct |
25 | Correct | 144 ms | 15736 KB | Output is correct |
26 | Correct | 145 ms | 15760 KB | Output is correct |
27 | Incorrect | 12 ms | 12024 KB | Output isn't correct |
28 | Halted | 0 ms | 0 KB | - |