# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
56003 |
2018-07-09T10:01:01 Z |
김세빈(#1563) |
Sushi (JOI16_sushi) |
C++11 |
|
4487 ms |
83416 KB |
#include <bits/stdc++.h>
using namespace std;
int sz = 600;
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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
436 KB |
Output is correct |
2 |
Correct |
23 ms |
484 KB |
Output is correct |
3 |
Correct |
25 ms |
484 KB |
Output is correct |
4 |
Correct |
24 ms |
484 KB |
Output is correct |
5 |
Correct |
20 ms |
484 KB |
Output is correct |
6 |
Correct |
25 ms |
496 KB |
Output is correct |
7 |
Correct |
18 ms |
624 KB |
Output is correct |
8 |
Correct |
19 ms |
624 KB |
Output is correct |
9 |
Correct |
22 ms |
696 KB |
Output is correct |
10 |
Correct |
27 ms |
696 KB |
Output is correct |
11 |
Correct |
27 ms |
696 KB |
Output is correct |
12 |
Correct |
27 ms |
696 KB |
Output is correct |
13 |
Correct |
26 ms |
696 KB |
Output is correct |
14 |
Correct |
18 ms |
784 KB |
Output is correct |
15 |
Correct |
16 ms |
784 KB |
Output is correct |
16 |
Correct |
11 ms |
784 KB |
Output is correct |
17 |
Correct |
3 ms |
784 KB |
Output is correct |
18 |
Correct |
2 ms |
784 KB |
Output is correct |
19 |
Correct |
3 ms |
784 KB |
Output is correct |
20 |
Correct |
2 ms |
784 KB |
Output is correct |
21 |
Correct |
2 ms |
784 KB |
Output is correct |
22 |
Correct |
2 ms |
784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3462 ms |
82832 KB |
Output is correct |
2 |
Correct |
3568 ms |
82832 KB |
Output is correct |
3 |
Correct |
322 ms |
82832 KB |
Output is correct |
4 |
Correct |
3645 ms |
83012 KB |
Output is correct |
5 |
Correct |
2953 ms |
83012 KB |
Output is correct |
6 |
Correct |
3453 ms |
83012 KB |
Output is correct |
7 |
Correct |
4179 ms |
83012 KB |
Output is correct |
8 |
Correct |
3772 ms |
83012 KB |
Output is correct |
9 |
Correct |
309 ms |
83012 KB |
Output is correct |
10 |
Correct |
2770 ms |
83012 KB |
Output is correct |
11 |
Correct |
294 ms |
83012 KB |
Output is correct |
12 |
Correct |
2830 ms |
83012 KB |
Output is correct |
13 |
Correct |
3277 ms |
83416 KB |
Output is correct |
14 |
Correct |
3329 ms |
83416 KB |
Output is correct |
15 |
Correct |
300 ms |
83416 KB |
Output is correct |
16 |
Correct |
3376 ms |
83416 KB |
Output is correct |
17 |
Correct |
2978 ms |
83416 KB |
Output is correct |
18 |
Correct |
4008 ms |
83416 KB |
Output is correct |
19 |
Correct |
3843 ms |
83416 KB |
Output is correct |
20 |
Correct |
3592 ms |
83416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
436 KB |
Output is correct |
2 |
Correct |
23 ms |
484 KB |
Output is correct |
3 |
Correct |
25 ms |
484 KB |
Output is correct |
4 |
Correct |
24 ms |
484 KB |
Output is correct |
5 |
Correct |
20 ms |
484 KB |
Output is correct |
6 |
Correct |
25 ms |
496 KB |
Output is correct |
7 |
Correct |
18 ms |
624 KB |
Output is correct |
8 |
Correct |
19 ms |
624 KB |
Output is correct |
9 |
Correct |
22 ms |
696 KB |
Output is correct |
10 |
Correct |
27 ms |
696 KB |
Output is correct |
11 |
Correct |
27 ms |
696 KB |
Output is correct |
12 |
Correct |
27 ms |
696 KB |
Output is correct |
13 |
Correct |
26 ms |
696 KB |
Output is correct |
14 |
Correct |
18 ms |
784 KB |
Output is correct |
15 |
Correct |
16 ms |
784 KB |
Output is correct |
16 |
Correct |
11 ms |
784 KB |
Output is correct |
17 |
Correct |
3 ms |
784 KB |
Output is correct |
18 |
Correct |
2 ms |
784 KB |
Output is correct |
19 |
Correct |
3 ms |
784 KB |
Output is correct |
20 |
Correct |
2 ms |
784 KB |
Output is correct |
21 |
Correct |
2 ms |
784 KB |
Output is correct |
22 |
Correct |
2 ms |
784 KB |
Output is correct |
23 |
Correct |
3462 ms |
82832 KB |
Output is correct |
24 |
Correct |
3568 ms |
82832 KB |
Output is correct |
25 |
Correct |
322 ms |
82832 KB |
Output is correct |
26 |
Correct |
3645 ms |
83012 KB |
Output is correct |
27 |
Correct |
2953 ms |
83012 KB |
Output is correct |
28 |
Correct |
3453 ms |
83012 KB |
Output is correct |
29 |
Correct |
4179 ms |
83012 KB |
Output is correct |
30 |
Correct |
3772 ms |
83012 KB |
Output is correct |
31 |
Correct |
309 ms |
83012 KB |
Output is correct |
32 |
Correct |
2770 ms |
83012 KB |
Output is correct |
33 |
Correct |
294 ms |
83012 KB |
Output is correct |
34 |
Correct |
2830 ms |
83012 KB |
Output is correct |
35 |
Correct |
3277 ms |
83416 KB |
Output is correct |
36 |
Correct |
3329 ms |
83416 KB |
Output is correct |
37 |
Correct |
300 ms |
83416 KB |
Output is correct |
38 |
Correct |
3376 ms |
83416 KB |
Output is correct |
39 |
Correct |
2978 ms |
83416 KB |
Output is correct |
40 |
Correct |
4008 ms |
83416 KB |
Output is correct |
41 |
Correct |
3843 ms |
83416 KB |
Output is correct |
42 |
Correct |
3592 ms |
83416 KB |
Output is correct |
43 |
Correct |
859 ms |
83416 KB |
Output is correct |
44 |
Correct |
840 ms |
83416 KB |
Output is correct |
45 |
Correct |
461 ms |
83416 KB |
Output is correct |
46 |
Correct |
867 ms |
83416 KB |
Output is correct |
47 |
Correct |
913 ms |
83416 KB |
Output is correct |
48 |
Correct |
2951 ms |
83416 KB |
Output is correct |
49 |
Correct |
3050 ms |
83416 KB |
Output is correct |
50 |
Correct |
2907 ms |
83416 KB |
Output is correct |
51 |
Correct |
3026 ms |
83416 KB |
Output is correct |
52 |
Correct |
735 ms |
83416 KB |
Output is correct |
53 |
Correct |
788 ms |
83416 KB |
Output is correct |
54 |
Correct |
3247 ms |
83416 KB |
Output is correct |
55 |
Correct |
3153 ms |
83416 KB |
Output is correct |
56 |
Correct |
3033 ms |
83416 KB |
Output is correct |
57 |
Correct |
2922 ms |
83416 KB |
Output is correct |
58 |
Correct |
2711 ms |
83416 KB |
Output is correct |
59 |
Correct |
3285 ms |
83416 KB |
Output is correct |
60 |
Correct |
3767 ms |
83416 KB |
Output is correct |
61 |
Correct |
4487 ms |
83416 KB |
Output is correct |
62 |
Correct |
4292 ms |
83416 KB |
Output is correct |
63 |
Correct |
4236 ms |
83416 KB |
Output is correct |
64 |
Correct |
435 ms |
83416 KB |
Output is correct |
65 |
Correct |
1822 ms |
83416 KB |
Output is correct |
66 |
Correct |
1769 ms |
83416 KB |
Output is correct |
67 |
Correct |
2494 ms |
83416 KB |
Output is correct |
68 |
Correct |
2787 ms |
83416 KB |
Output is correct |
69 |
Correct |
2860 ms |
83416 KB |
Output is correct |
70 |
Correct |
2813 ms |
83416 KB |
Output is correct |