Submission #218498

# Submission time Handle Problem Language Result Execution time Memory
218498 2020-04-02T08:29:26 Z patrikpavic2 Long Mansion (JOI17_long_mansion) C++17
100 / 100
664 ms 50432 KB
#include <cstdio>
#include <vector>

#define X first
#define Y second
#define PB push_back

using namespace std;

const int N = 5e5 + 500;

int c[N], L[N], R[N], ima[N], tL[N], tR[N], C[N];
vector < int > mogu[N];

inline void clean(int l,int r){
	for(int i = l;i < r;i++){
		for(int x : mogu[i])
			ima[x] = 0;
	}
}

inline void ubaci(int i){
	for(int x : mogu[i])
		ima[x] = 1;
}

inline void siri(int l,int r, int &cL, int &cR){
	for(;;){
		if(cL > l && ima[C[cL - 1]]){
			cL--; 
			if(cL != l) 
				ubaci(cL - 1);
			continue;
		}
		if(cR < r && ima[C[cR + 1]]){
			cR++;
			if(cR != r) 
				ubaci(cR);
			continue;
		}
		break;
	}
}


void rijesi(int l,int r){
	if(l == r) return;
	//printf("l = %d r = %d\n", l, r);
	if(l + 1 == r){
		ubaci(l);
		L[l] = r, R[l] = l;
		if(ima[C[l]]) 
			L[l] = l;
		if(ima[C[r]]) 
			R[l] = r;
		clean(l, r);
		//printf("L[ %d ] = %d , R[ %d ] = %d\n", 3, L[3], 3, R[3]);
		return;
	}
	int mid = (l + r) / 2;
	rijesi(l, mid); rijesi(mid, r);
	int cL = mid, cR = mid - 1;
	if(mid - 1 >= l)
		ubaci(mid - 1);
	for(int ll = mid - 1;ll >= l;ll--){
		if(cL > ll + 1){
			ubaci(ll); cL = ll + 1;
		}
		siri(l, r, cL, cR);		
		tL[ll] = cL, tR[ll] = cR;
	}
	clean(l, r);
	cL = mid + 1, cR = mid;
	ubaci(mid);
	for(int rr = mid;rr < r;rr++){
		if(cR <= rr){
			ubaci(rr); cR = rr;
		}
		siri(l, r, cL, cR);
		tL[rr] = cL, tR[rr] = cR;
	//	printf("cL = %d cR = %d\n", cL, cR);
	}
	//printf("(%d %d)  L[ %d ] = %d , R[ %d ] = %d\n", l, r, 3, tL[3], 3, tR[3]);
	clean(l, r);
	for(int i = l;i < mid;i++){
		if(R[i] == mid)
			L[i] = tL[max(L[i] - 1, l)], R[i] = tR[max(L[i] - 1, l)];
	}
	for(int i = mid;i < r;i++){
		if(L[i] == mid)
			L[i] = tL[min(R[i], r - 1)], R[i] = tR[min(R[i], r - 1)];
	}
	//printf("(%d %d)  L[ %d ] = %d , R[ %d ] = %d\n", l, r, 3, L[3], 3, R[3]);
	return;
}

int n, q;

int main(){
	scanf("%d", &n);
	for(int i = 1;i < n;i++)
		scanf("%d", C + i);
	for(int i = 0;i < n;i++){
		int kol; scanf("%d", &kol);
		for(;kol--;){
			int x; scanf("%d", &x);
			mogu[i].PB(x);
		}
	}
	//for(int i = 0;i <= n;i++){
	//	printf("%d == ", C[i]);
	//	if(i != n){
	//		printf("[ ");
	//		for(int x : mogu[i]) printf("%d ", x);
	//		printf("] == ");
	//	}
	//}
	//printf("\n");
	rijesi(0, n);
	//for(int i = 0;i < n;i++){
	//	printf("i = %d interval %d %d\n", i, L[i] - 1, R[i]);
	//}
	scanf("%d", &q);
	for(;q--;){
		int x, y; scanf("%d%d", &x, &y); x--, y--;
		printf((L[x] - 1 <= y && y <= R[x]) ? "YES\n" : "NO\n");
	}
}















Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:100:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
long_mansion.cpp:102:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", C + i);
   ~~~~~^~~~~~~~~~~~~
long_mansion.cpp:104:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int kol; scanf("%d", &kol);
            ~~~~~^~~~~~~~~~~~
long_mansion.cpp:106:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int x; scanf("%d", &x);
           ~~~~~^~~~~~~~~~
long_mansion.cpp:123:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
long_mansion.cpp:125:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y); x--, y--;
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12160 KB Output is correct
2 Correct 16 ms 12288 KB Output is correct
3 Correct 17 ms 12416 KB Output is correct
4 Correct 15 ms 12288 KB Output is correct
5 Correct 15 ms 12288 KB Output is correct
6 Correct 15 ms 12288 KB Output is correct
7 Correct 14 ms 12288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12160 KB Output is correct
2 Correct 16 ms 12288 KB Output is correct
3 Correct 17 ms 12416 KB Output is correct
4 Correct 15 ms 12288 KB Output is correct
5 Correct 15 ms 12288 KB Output is correct
6 Correct 15 ms 12288 KB Output is correct
7 Correct 14 ms 12288 KB Output is correct
8 Correct 166 ms 16736 KB Output is correct
9 Correct 158 ms 18040 KB Output is correct
10 Correct 156 ms 18424 KB Output is correct
11 Correct 158 ms 18936 KB Output is correct
12 Correct 145 ms 17784 KB Output is correct
13 Correct 147 ms 18456 KB Output is correct
14 Correct 155 ms 18296 KB Output is correct
15 Correct 150 ms 18296 KB Output is correct
16 Correct 149 ms 18348 KB Output is correct
17 Correct 152 ms 18296 KB Output is correct
18 Correct 153 ms 18296 KB Output is correct
19 Correct 159 ms 18404 KB Output is correct
20 Correct 151 ms 18308 KB Output is correct
21 Correct 141 ms 18200 KB Output is correct
22 Correct 152 ms 18168 KB Output is correct
23 Correct 151 ms 18040 KB Output is correct
24 Correct 155 ms 18168 KB Output is correct
25 Correct 158 ms 18124 KB Output is correct
26 Correct 158 ms 18040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 413 ms 19656 KB Output is correct
2 Correct 388 ms 26616 KB Output is correct
3 Correct 381 ms 26488 KB Output is correct
4 Correct 403 ms 26744 KB Output is correct
5 Correct 393 ms 26744 KB Output is correct
6 Correct 299 ms 25464 KB Output is correct
7 Correct 292 ms 25208 KB Output is correct
8 Correct 290 ms 25372 KB Output is correct
9 Correct 275 ms 25208 KB Output is correct
10 Correct 281 ms 25204 KB Output is correct
11 Correct 270 ms 25208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 12160 KB Output is correct
2 Correct 16 ms 12288 KB Output is correct
3 Correct 17 ms 12416 KB Output is correct
4 Correct 15 ms 12288 KB Output is correct
5 Correct 15 ms 12288 KB Output is correct
6 Correct 15 ms 12288 KB Output is correct
7 Correct 14 ms 12288 KB Output is correct
8 Correct 166 ms 16736 KB Output is correct
9 Correct 158 ms 18040 KB Output is correct
10 Correct 156 ms 18424 KB Output is correct
11 Correct 158 ms 18936 KB Output is correct
12 Correct 145 ms 17784 KB Output is correct
13 Correct 147 ms 18456 KB Output is correct
14 Correct 155 ms 18296 KB Output is correct
15 Correct 150 ms 18296 KB Output is correct
16 Correct 149 ms 18348 KB Output is correct
17 Correct 152 ms 18296 KB Output is correct
18 Correct 153 ms 18296 KB Output is correct
19 Correct 159 ms 18404 KB Output is correct
20 Correct 151 ms 18308 KB Output is correct
21 Correct 141 ms 18200 KB Output is correct
22 Correct 152 ms 18168 KB Output is correct
23 Correct 151 ms 18040 KB Output is correct
24 Correct 155 ms 18168 KB Output is correct
25 Correct 158 ms 18124 KB Output is correct
26 Correct 158 ms 18040 KB Output is correct
27 Correct 413 ms 19656 KB Output is correct
28 Correct 388 ms 26616 KB Output is correct
29 Correct 381 ms 26488 KB Output is correct
30 Correct 403 ms 26744 KB Output is correct
31 Correct 393 ms 26744 KB Output is correct
32 Correct 299 ms 25464 KB Output is correct
33 Correct 292 ms 25208 KB Output is correct
34 Correct 290 ms 25372 KB Output is correct
35 Correct 275 ms 25208 KB Output is correct
36 Correct 281 ms 25204 KB Output is correct
37 Correct 270 ms 25208 KB Output is correct
38 Correct 584 ms 45756 KB Output is correct
39 Correct 611 ms 50432 KB Output is correct
40 Correct 580 ms 39544 KB Output is correct
41 Correct 664 ms 49016 KB Output is correct
42 Correct 296 ms 26616 KB Output is correct
43 Correct 298 ms 26512 KB Output is correct
44 Correct 426 ms 34424 KB Output is correct
45 Correct 426 ms 34936 KB Output is correct
46 Correct 433 ms 35064 KB Output is correct
47 Correct 293 ms 26620 KB Output is correct
48 Correct 291 ms 26388 KB Output is correct
49 Correct 434 ms 34268 KB Output is correct
50 Correct 437 ms 34636 KB Output is correct
51 Correct 447 ms 35448 KB Output is correct
52 Correct 339 ms 33784 KB Output is correct
53 Correct 442 ms 41080 KB Output is correct
54 Correct 531 ms 47992 KB Output is correct
55 Correct 424 ms 41080 KB Output is correct