# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
260710 | 2020-08-10T18:52:35 Z | fadi57 | Long Mansion (JOI17_long_mansion) | C++14 | 3000 ms | 24128 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long const int mx=500020; int c[mx]; int b[mx]; vector<int>keys[mx]; int mxright[mx]; int mxleft[mx]; int n,m; int leftt[mx];int rightt[mx]; int last[mx]; int canr(int i){ if(leftt[mxright[i]]>=mxleft[i]&&leftt[mxright[i]]!=-1&&mxright[i]<n){ return 1; }return 0; }int canl(int i){ if(rightt[mxleft[i]-1]<=mxright[i]&&rightt[mxleft[i]-1]!=-1&&mxleft[i]>1){ return 1; }return 0; } int main() { scanf("%d",&n); for(ll i=1;i<n;i++){ scanf("%d",&c[i]); } for(int i=1;i<=n;i++){ scanf("%d",&b[i]); for(int j=0;j<b[i];j++){ int x; scanf("%d",&x); keys[i].push_back(x); } } memset(last ,-1 ,sizeof last); for(int i=1;i<n;i++){ for(int j:keys[i]){ last[j]=i; } leftt[i]=last[c[i]]; } memset(last ,-1 ,sizeof last); for(int i=n-1;i>=1;i--){ for(int j:keys[i+1]){ last[j]=i+1; } rightt[i]=last[c[i]]; } for(int i=1;i<=n;i++){ int myr=i; int myl=i; mxleft[i]=i; mxright[i]=i; while(1){ int xx=0;ll xo=0; if(canl(i)){ xo=1; myl--; mxleft[i]=myl; mxleft[i]=min(mxleft[i],mxleft[mxleft[i]]); mxright[i]=max(mxright[i],mxright[mxleft[i]]); }else if(canr(i)){ xx=1; myr++; mxright[i]=myr; }else {break;} } } int q;cin>>q; for(int i=0;i<q;i++){ int x,y; scanf("%d%d",&x,&y); //cout<<mxleft[x]<<" "<<mxright[x]; printf(mxleft[x] <= y && y <= mxright[x] ? "YES\n" : "NO\n") <<'\n'; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 14208 KB | Output is correct |
2 | Correct | 15 ms | 14336 KB | Output is correct |
3 | Correct | 25 ms | 14464 KB | Output is correct |
4 | Correct | 12 ms | 14208 KB | Output is correct |
5 | Correct | 12 ms | 14208 KB | Output is correct |
6 | Correct | 12 ms | 14208 KB | Output is correct |
7 | Correct | 13 ms | 14208 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 14208 KB | Output is correct |
2 | Correct | 15 ms | 14336 KB | Output is correct |
3 | Correct | 25 ms | 14464 KB | Output is correct |
4 | Correct | 12 ms | 14208 KB | Output is correct |
5 | Correct | 12 ms | 14208 KB | Output is correct |
6 | Correct | 12 ms | 14208 KB | Output is correct |
7 | Correct | 13 ms | 14208 KB | Output is correct |
8 | Correct | 170 ms | 16248 KB | Output is correct |
9 | Correct | 169 ms | 16248 KB | Output is correct |
10 | Correct | 179 ms | 16660 KB | Output is correct |
11 | Correct | 183 ms | 16844 KB | Output is correct |
12 | Correct | 164 ms | 16376 KB | Output is correct |
13 | Correct | 165 ms | 16504 KB | Output is correct |
14 | Correct | 161 ms | 16504 KB | Output is correct |
15 | Correct | 164 ms | 16632 KB | Output is correct |
16 | Correct | 153 ms | 16764 KB | Output is correct |
17 | Correct | 164 ms | 16504 KB | Output is correct |
18 | Correct | 163 ms | 16480 KB | Output is correct |
19 | Correct | 170 ms | 16504 KB | Output is correct |
20 | Correct | 167 ms | 16636 KB | Output is correct |
21 | Correct | 153 ms | 16760 KB | Output is correct |
22 | Correct | 164 ms | 16504 KB | Output is correct |
23 | Correct | 174 ms | 16248 KB | Output is correct |
24 | Correct | 167 ms | 16228 KB | Output is correct |
25 | Correct | 167 ms | 16432 KB | Output is correct |
26 | Correct | 180 ms | 16376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1118 ms | 22324 KB | Output is correct |
2 | Correct | 2130 ms | 24128 KB | Output is correct |
3 | Execution timed out | 3076 ms | 21236 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 14208 KB | Output is correct |
2 | Correct | 15 ms | 14336 KB | Output is correct |
3 | Correct | 25 ms | 14464 KB | Output is correct |
4 | Correct | 12 ms | 14208 KB | Output is correct |
5 | Correct | 12 ms | 14208 KB | Output is correct |
6 | Correct | 12 ms | 14208 KB | Output is correct |
7 | Correct | 13 ms | 14208 KB | Output is correct |
8 | Correct | 170 ms | 16248 KB | Output is correct |
9 | Correct | 169 ms | 16248 KB | Output is correct |
10 | Correct | 179 ms | 16660 KB | Output is correct |
11 | Correct | 183 ms | 16844 KB | Output is correct |
12 | Correct | 164 ms | 16376 KB | Output is correct |
13 | Correct | 165 ms | 16504 KB | Output is correct |
14 | Correct | 161 ms | 16504 KB | Output is correct |
15 | Correct | 164 ms | 16632 KB | Output is correct |
16 | Correct | 153 ms | 16764 KB | Output is correct |
17 | Correct | 164 ms | 16504 KB | Output is correct |
18 | Correct | 163 ms | 16480 KB | Output is correct |
19 | Correct | 170 ms | 16504 KB | Output is correct |
20 | Correct | 167 ms | 16636 KB | Output is correct |
21 | Correct | 153 ms | 16760 KB | Output is correct |
22 | Correct | 164 ms | 16504 KB | Output is correct |
23 | Correct | 174 ms | 16248 KB | Output is correct |
24 | Correct | 167 ms | 16228 KB | Output is correct |
25 | Correct | 167 ms | 16432 KB | Output is correct |
26 | Correct | 180 ms | 16376 KB | Output is correct |
27 | Correct | 1118 ms | 22324 KB | Output is correct |
28 | Correct | 2130 ms | 24128 KB | Output is correct |
29 | Execution timed out | 3076 ms | 21236 KB | Time limit exceeded |
30 | Halted | 0 ms | 0 KB | - |