Submission #56001

# Submission time Handle Problem Language Result Execution time Memory
56001 2018-07-09T09:59:57 Z 김세빈(#1563) Sushi (JOI16_sushi) C++11
100 / 100
4826 ms 98452 KB
#include <bits/stdc++.h>

using namespace std;

int sz = 500;

int A[404040], H[404040];
int B[404040], L[1010], R[1010];
priority_queue <int, vector<int>, greater<int>> Q[1010];
int n, k;

void spread(int x)
{
	if(Q[x].empty()) return;
	
	int i;
	
	for(i=L[x];i<=R[x];i++){
		if(A[i] > Q[x].top()){
			Q[x].push(A[i]);
			A[i] = Q[x].top(); Q[x].pop();
		}
	}
	
	for(;!Q[x].empty();) Q[x].pop();
}

int main()
{
	int q, i, a, b, c, x, y;
	
	scanf("%d%d", &n, &q);
	
	for(i=0;i<n;i++){
		scanf("%d", A+i);
		H[i] = A[i]; B[i] = i/sz;
		if(i % sz == 0) L[i/sz] = i;
		R[i/sz] = i;
	}
	
	k = (n - 1) / sz + 1;
	
	for(i=0;i<k;i++){
		make_heap(H + L[i], H + R[i] + 1);
	}
	
	for(;q--;){
		scanf("%d%d%d", &a, &b, &c);
		a --, b --;
		x = B[a], y = B[b];
		
		if(x == y){
			if(a <= b){
				spread(x);
				for(i=a;i<=b;i++){
					if(A[i] > c) swap(A[i], c);
				}
				
				for(i=L[x];i<=R[x];i++) H[i] = A[i];
				make_heap(H + L[x], H + R[x] + 1);
				
				printf("%d\n", c);
			}
			else{
				spread(x);
				for(i=a;i<=R[x];i++){
					if(A[i] > c) swap(A[i], c);
				}
				x = (x + 1) % k;
				
				for(;x!=y;x=(x+1)%k){
					if(H[L[x]] > c){
						Q[x].push(c);
						pop_heap(H + L[x], H + R[x] + 1);
						swap(c, H[R[x]]);
						push_heap(H + L[x], H + R[x] + 1);
					}
				}
				
				for(i=L[x];i<=b;i++){
					if(A[i] > c) swap(A[i], c);
				}
				
				for(i=L[x];i<=R[x];i++) H[i] = A[i];
				make_heap(H + L[x], H + R[x] + 1);
				
				printf("%d\n", c);
			}
		}
		else{
			if(L[x] != a){
				spread(x);
				
				for(i=a;i<=R[x];i++){
					if(A[i] > c) swap(A[i], c);
				}
				
				for(i=L[x];i<=R[x];i++) H[i] = A[i];
				make_heap(H + L[x], H + R[x] + 1);
				
				x = (x + 1) % k;
			}
			
			
			for(;x!=y;x=(x+1)%k){
				if(H[L[x]] > c){
					Q[x].push(c);
					pop_heap(H + L[x], H + R[x] + 1);
					swap(c, H[R[x]]);
					push_heap(H + L[x], H + R[x] + 1);
				}
			}
					
			spread(y);
			for(i=L[y];i<=b;i++){
				if(A[i] > c) swap(A[i], c);
			}
			
			for(i=L[y];i<=R[y];i++) H[i] = A[i];
			make_heap(H + L[y], H + R[y] + 1);

			printf("%d\n", c);
		}
	}
	
	return 0;
}

Compilation message

telegraph.cpp: In function 'int main()':
telegraph.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~
telegraph.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", A+i);
   ~~~~~^~~~~~~~~~~
telegraph.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 504 KB Output is correct
2 Correct 20 ms 504 KB Output is correct
3 Correct 22 ms 536 KB Output is correct
4 Correct 27 ms 536 KB Output is correct
5 Correct 20 ms 536 KB Output is correct
6 Correct 22 ms 536 KB Output is correct
7 Correct 18 ms 536 KB Output is correct
8 Correct 22 ms 628 KB Output is correct
9 Correct 26 ms 628 KB Output is correct
10 Correct 22 ms 628 KB Output is correct
11 Correct 33 ms 628 KB Output is correct
12 Correct 30 ms 720 KB Output is correct
13 Correct 38 ms 720 KB Output is correct
14 Correct 21 ms 720 KB Output is correct
15 Correct 17 ms 736 KB Output is correct
16 Correct 16 ms 812 KB Output is correct
17 Correct 2 ms 812 KB Output is correct
18 Correct 2 ms 812 KB Output is correct
19 Correct 2 ms 812 KB Output is correct
20 Correct 3 ms 812 KB Output is correct
21 Correct 2 ms 812 KB Output is correct
22 Correct 3 ms 812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4474 ms 98332 KB Output is correct
2 Correct 4434 ms 98332 KB Output is correct
3 Correct 365 ms 98332 KB Output is correct
4 Correct 4273 ms 98332 KB Output is correct
5 Correct 3604 ms 98332 KB Output is correct
6 Correct 4264 ms 98332 KB Output is correct
7 Correct 4389 ms 98332 KB Output is correct
8 Correct 4229 ms 98332 KB Output is correct
9 Correct 388 ms 98332 KB Output is correct
10 Correct 3681 ms 98332 KB Output is correct
11 Correct 352 ms 98332 KB Output is correct
12 Correct 3305 ms 98332 KB Output is correct
13 Correct 4396 ms 98332 KB Output is correct
14 Correct 4402 ms 98452 KB Output is correct
15 Correct 351 ms 98452 KB Output is correct
16 Correct 3931 ms 98452 KB Output is correct
17 Correct 3474 ms 98452 KB Output is correct
18 Correct 4826 ms 98452 KB Output is correct
19 Correct 4661 ms 98452 KB Output is correct
20 Correct 4603 ms 98452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 504 KB Output is correct
2 Correct 20 ms 504 KB Output is correct
3 Correct 22 ms 536 KB Output is correct
4 Correct 27 ms 536 KB Output is correct
5 Correct 20 ms 536 KB Output is correct
6 Correct 22 ms 536 KB Output is correct
7 Correct 18 ms 536 KB Output is correct
8 Correct 22 ms 628 KB Output is correct
9 Correct 26 ms 628 KB Output is correct
10 Correct 22 ms 628 KB Output is correct
11 Correct 33 ms 628 KB Output is correct
12 Correct 30 ms 720 KB Output is correct
13 Correct 38 ms 720 KB Output is correct
14 Correct 21 ms 720 KB Output is correct
15 Correct 17 ms 736 KB Output is correct
16 Correct 16 ms 812 KB Output is correct
17 Correct 2 ms 812 KB Output is correct
18 Correct 2 ms 812 KB Output is correct
19 Correct 2 ms 812 KB Output is correct
20 Correct 3 ms 812 KB Output is correct
21 Correct 2 ms 812 KB Output is correct
22 Correct 3 ms 812 KB Output is correct
23 Correct 4474 ms 98332 KB Output is correct
24 Correct 4434 ms 98332 KB Output is correct
25 Correct 365 ms 98332 KB Output is correct
26 Correct 4273 ms 98332 KB Output is correct
27 Correct 3604 ms 98332 KB Output is correct
28 Correct 4264 ms 98332 KB Output is correct
29 Correct 4389 ms 98332 KB Output is correct
30 Correct 4229 ms 98332 KB Output is correct
31 Correct 388 ms 98332 KB Output is correct
32 Correct 3681 ms 98332 KB Output is correct
33 Correct 352 ms 98332 KB Output is correct
34 Correct 3305 ms 98332 KB Output is correct
35 Correct 4396 ms 98332 KB Output is correct
36 Correct 4402 ms 98452 KB Output is correct
37 Correct 351 ms 98452 KB Output is correct
38 Correct 3931 ms 98452 KB Output is correct
39 Correct 3474 ms 98452 KB Output is correct
40 Correct 4826 ms 98452 KB Output is correct
41 Correct 4661 ms 98452 KB Output is correct
42 Correct 4603 ms 98452 KB Output is correct
43 Correct 885 ms 98452 KB Output is correct
44 Correct 832 ms 98452 KB Output is correct
45 Correct 508 ms 98452 KB Output is correct
46 Correct 767 ms 98452 KB Output is correct
47 Correct 746 ms 98452 KB Output is correct
48 Correct 2755 ms 98452 KB Output is correct
49 Correct 2937 ms 98452 KB Output is correct
50 Correct 3306 ms 98452 KB Output is correct
51 Correct 3145 ms 98452 KB Output is correct
52 Correct 803 ms 98452 KB Output is correct
53 Correct 810 ms 98452 KB Output is correct
54 Correct 3197 ms 98452 KB Output is correct
55 Correct 3150 ms 98452 KB Output is correct
56 Correct 3068 ms 98452 KB Output is correct
57 Correct 3065 ms 98452 KB Output is correct
58 Correct 2874 ms 98452 KB Output is correct
59 Correct 3027 ms 98452 KB Output is correct
60 Correct 4147 ms 98452 KB Output is correct
61 Correct 4667 ms 98452 KB Output is correct
62 Correct 4288 ms 98452 KB Output is correct
63 Correct 4665 ms 98452 KB Output is correct
64 Correct 397 ms 98452 KB Output is correct
65 Correct 1667 ms 98452 KB Output is correct
66 Correct 1728 ms 98452 KB Output is correct
67 Correct 2315 ms 98452 KB Output is correct
68 Correct 3075 ms 98452 KB Output is correct
69 Correct 2900 ms 98452 KB Output is correct
70 Correct 3289 ms 98452 KB Output is correct