# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
125315 | 2019-07-05T05:33:58 Z | 박상수(#3065) | Long Mansion (JOI17_long_mansion) | C++14 | 522 ms | 57720 KB |
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <stack> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <iostream> #include <functional> #include <unordered_set> #include <bitset> #include <time.h> #include <limits.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define Fi first #define Se second #define pb push_back #define szz(x) (int)x.size() #define rep(i,n) for(int i=0;i<n;i++) #define all(x) x.begin(),x.end() typedef tuple<int, int, int> t3; int N, C[500050], Q; vector <int> B[500050], Ins[500050]; int last[500050], pre[500050], nxt[500050]; pii ans[500050]; void upd(pii &p, pii a) { p.Fi = max(p.Fi, a.Fi); p.Se = min(p.Se, a.Se); } int Temp[500050]; void Do(int l, int r) { if(l == r) { if(nxt[l] >= l && pre[l] <= l) { ans[l] = pii(l, l); } return; } int m = (l + r) >> 1; for(int i=l;i<=m;i++) Temp[i] = 1e9; for(int i=m+1;i<=r;i++) { if(pre[i] <= m) { int pp = max(pre[i], l); Temp[pp] = min(Temp[pp], i); } } for(int i=l+1;i<=m;i++) Temp[i] = min(Temp[i], Temp[i-1]); pii now = pii(1, N); for(int i=l;i<=m;i++) { if(nxt[i] >= Temp[i]) { upd(now, pii(i, Temp[i])); } upd(ans[i], now); } for(int i=m+1;i<=r;i++) Temp[i] = -1e9; for(int i=l;i<=m;i++) { if(nxt[i] > m) { int nn = min(nxt[i], r); Temp[nn] = max(Temp[nn], i); } } for(int i=r-1;i>m;i--) Temp[i] = max(Temp[i], Temp[i+1]); now = pii(1, N); for(int i=r;i>m;i--) { if(pre[i] <= Temp[i]) { upd(now, pii(Temp[i], i)); } upd(ans[i], now); } Do(l, m); Do(m+1, r); } int main() { scanf("%d", &N); for(int i=2;i<=N;i++) scanf("%d", C + i); for(int i=1;i<=N;i++) { int x; scanf("%d", &x); rep(j, x) { int a; scanf("%d", &a); B[i].pb(a); } } for(int i=1;i<=N;i++) { for(int e : B[i]) last[e] = i; if(i < N) { pre[i] = last[C[i+1]] + 1; } else pre[i] = 1; } rep(i, 500050) last[i] = N + 1; for(int i=N;i;i--) { for(int e : B[i]) last[e] = i; if(i > 1) { nxt[i] = last[C[i]] - 1; } else nxt[i] = N; } for(int i=1;i<=N;i++) ans[i] = pii(1, N); Do(1, N); scanf("%d", &Q); for(int i=1;i<=Q;i++) { int x, y; scanf("%d%d", &x, &y); if(ans[x].Fi <= y && y <= ans[x].Se) { puts("YES"); } else puts("NO"); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 25976 KB | Output is correct |
2 | Correct | 29 ms | 26104 KB | Output is correct |
3 | Correct | 29 ms | 26232 KB | Output is correct |
4 | Correct | 28 ms | 25976 KB | Output is correct |
5 | Correct | 28 ms | 25976 KB | Output is correct |
6 | Correct | 28 ms | 25976 KB | Output is correct |
7 | Correct | 27 ms | 25976 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 25976 KB | Output is correct |
2 | Correct | 29 ms | 26104 KB | Output is correct |
3 | Correct | 29 ms | 26232 KB | Output is correct |
4 | Correct | 28 ms | 25976 KB | Output is correct |
5 | Correct | 28 ms | 25976 KB | Output is correct |
6 | Correct | 28 ms | 25976 KB | Output is correct |
7 | Correct | 27 ms | 25976 KB | Output is correct |
8 | Correct | 156 ms | 30200 KB | Output is correct |
9 | Correct | 155 ms | 30200 KB | Output is correct |
10 | Correct | 159 ms | 30456 KB | Output is correct |
11 | Correct | 156 ms | 30584 KB | Output is correct |
12 | Correct | 147 ms | 30496 KB | Output is correct |
13 | Correct | 151 ms | 30428 KB | Output is correct |
14 | Correct | 160 ms | 30456 KB | Output is correct |
15 | Correct | 150 ms | 30584 KB | Output is correct |
16 | Correct | 146 ms | 30684 KB | Output is correct |
17 | Correct | 159 ms | 30428 KB | Output is correct |
18 | Correct | 150 ms | 30484 KB | Output is correct |
19 | Correct | 150 ms | 30456 KB | Output is correct |
20 | Correct | 149 ms | 30640 KB | Output is correct |
21 | Correct | 145 ms | 30728 KB | Output is correct |
22 | Correct | 150 ms | 30492 KB | Output is correct |
23 | Correct | 152 ms | 30328 KB | Output is correct |
24 | Correct | 152 ms | 30328 KB | Output is correct |
25 | Correct | 152 ms | 30300 KB | Output is correct |
26 | Correct | 158 ms | 30304 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 300 ms | 37576 KB | Output is correct |
2 | Correct | 314 ms | 36728 KB | Output is correct |
3 | Correct | 284 ms | 36640 KB | Output is correct |
4 | Correct | 297 ms | 36700 KB | Output is correct |
5 | Correct | 294 ms | 36728 KB | Output is correct |
6 | Correct | 234 ms | 36188 KB | Output is correct |
7 | Correct | 232 ms | 36472 KB | Output is correct |
8 | Correct | 234 ms | 36472 KB | Output is correct |
9 | Correct | 228 ms | 36668 KB | Output is correct |
10 | Correct | 232 ms | 36472 KB | Output is correct |
11 | Correct | 227 ms | 36344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 25976 KB | Output is correct |
2 | Correct | 29 ms | 26104 KB | Output is correct |
3 | Correct | 29 ms | 26232 KB | Output is correct |
4 | Correct | 28 ms | 25976 KB | Output is correct |
5 | Correct | 28 ms | 25976 KB | Output is correct |
6 | Correct | 28 ms | 25976 KB | Output is correct |
7 | Correct | 27 ms | 25976 KB | Output is correct |
8 | Correct | 156 ms | 30200 KB | Output is correct |
9 | Correct | 155 ms | 30200 KB | Output is correct |
10 | Correct | 159 ms | 30456 KB | Output is correct |
11 | Correct | 156 ms | 30584 KB | Output is correct |
12 | Correct | 147 ms | 30496 KB | Output is correct |
13 | Correct | 151 ms | 30428 KB | Output is correct |
14 | Correct | 160 ms | 30456 KB | Output is correct |
15 | Correct | 150 ms | 30584 KB | Output is correct |
16 | Correct | 146 ms | 30684 KB | Output is correct |
17 | Correct | 159 ms | 30428 KB | Output is correct |
18 | Correct | 150 ms | 30484 KB | Output is correct |
19 | Correct | 150 ms | 30456 KB | Output is correct |
20 | Correct | 149 ms | 30640 KB | Output is correct |
21 | Correct | 145 ms | 30728 KB | Output is correct |
22 | Correct | 150 ms | 30492 KB | Output is correct |
23 | Correct | 152 ms | 30328 KB | Output is correct |
24 | Correct | 152 ms | 30328 KB | Output is correct |
25 | Correct | 152 ms | 30300 KB | Output is correct |
26 | Correct | 158 ms | 30304 KB | Output is correct |
27 | Correct | 300 ms | 37576 KB | Output is correct |
28 | Correct | 314 ms | 36728 KB | Output is correct |
29 | Correct | 284 ms | 36640 KB | Output is correct |
30 | Correct | 297 ms | 36700 KB | Output is correct |
31 | Correct | 294 ms | 36728 KB | Output is correct |
32 | Correct | 234 ms | 36188 KB | Output is correct |
33 | Correct | 232 ms | 36472 KB | Output is correct |
34 | Correct | 234 ms | 36472 KB | Output is correct |
35 | Correct | 228 ms | 36668 KB | Output is correct |
36 | Correct | 232 ms | 36472 KB | Output is correct |
37 | Correct | 227 ms | 36344 KB | Output is correct |
38 | Correct | 499 ms | 52220 KB | Output is correct |
39 | Correct | 522 ms | 57592 KB | Output is correct |
40 | Correct | 442 ms | 46632 KB | Output is correct |
41 | Correct | 470 ms | 57720 KB | Output is correct |
42 | Correct | 253 ms | 35836 KB | Output is correct |
43 | Correct | 250 ms | 35960 KB | Output is correct |
44 | Correct | 348 ms | 41308 KB | Output is correct |
45 | Correct | 349 ms | 41208 KB | Output is correct |
46 | Correct | 348 ms | 41196 KB | Output is correct |
47 | Correct | 254 ms | 35960 KB | Output is correct |
48 | Correct | 255 ms | 36128 KB | Output is correct |
49 | Correct | 346 ms | 41080 KB | Output is correct |
50 | Correct | 343 ms | 41080 KB | Output is correct |
51 | Correct | 350 ms | 40952 KB | Output is correct |
52 | Correct | 336 ms | 40952 KB | Output is correct |
53 | Correct | 421 ms | 46032 KB | Output is correct |
54 | Correct | 475 ms | 51448 KB | Output is correct |
55 | Correct | 402 ms | 46128 KB | Output is correct |