Submission #199479

# Submission time Handle Problem Language Result Execution time Memory
199479 2020-02-01T14:10:58 Z dennisstar Sushi (JOI16_sushi) C++17
100 / 100
4569 ms 70516 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef vector<int> vim;
typedef pair<int, int> pii;
 
const int sz = 700;

int N, M, Q, X[400010];
priority_queue<int> S[1010], R[1010];

inline void upd(int t) {
	for (int i=t*sz; i<min((t+1)*sz, N); i++) {
		R[t].em(-X[i]);
		X[i]=-R[t].top();
		R[t].pop();
	}
	S[t]=R[t]=priority_queue<int>();
}
 
inline void sol(int t, int &p) {
	S[t].em(p); R[t].em(-p);
	p=S[t].top(); S[t].pop();
}

inline void make(int t) { for (int i=t*sz; i<min(N, (t+1)*sz); i++) S[t].em(X[i]); }

inline int f(int s, int e, int p) {
	int st=s/sz, et=e/sz;
	if (st==et) {
		upd(st);
		for (int i=s; i<=e; i++) if (p<X[i]) swap(p, X[i]);
		make(st);
	}
	else {
		upd(st); upd(et);
		for (int i=s; i<(st+1)*sz; i++) if (p<X[i]) swap(p, X[i]);
		for (int i=st+1; i<et; i++) sol(i, p);
		for (int i=et*sz; i<=e; i++) if (p<X[i]) swap(p, X[i]);
		make(st); make(et);
	}
	return p;
}
 
int main() {
	scanf("%d %d", &N, &Q); M=(N+sz-1)/sz;
	for (int i=0; i<N; i++) scanf("%d", &X[i]), S[i/sz].em(X[i]);
	while (Q--) {
		int s, t, p;
		scanf("%d %d %d", &s, &t, &p); s--; t--;
		if (s>t) printf("%d\n", f(0, t, f(s, N-1, p)));
		else printf("%d\n", f(s, t, p));
	}
	return 0;
}

Compilation message

sushi.cpp: In function 'int main()':
sushi.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &Q); M=(N+sz-1)/sz;
  ~~~~~^~~~~~~~~~~~~~~~~
sushi.cpp:51:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=0; i<N; i++) scanf("%d", &X[i]), S[i/sz].em(X[i]);
                          ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
sushi.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &s, &t, &p); s--; t--;
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 89 ms 376 KB Output is correct
2 Correct 90 ms 376 KB Output is correct
3 Correct 93 ms 380 KB Output is correct
4 Correct 89 ms 376 KB Output is correct
5 Correct 92 ms 376 KB Output is correct
6 Correct 91 ms 376 KB Output is correct
7 Correct 68 ms 376 KB Output is correct
8 Correct 71 ms 376 KB Output is correct
9 Correct 91 ms 504 KB Output is correct
10 Correct 120 ms 504 KB Output is correct
11 Correct 100 ms 376 KB Output is correct
12 Correct 110 ms 464 KB Output is correct
13 Correct 108 ms 504 KB Output is correct
14 Correct 126 ms 472 KB Output is correct
15 Correct 119 ms 504 KB Output is correct
16 Correct 38 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3514 ms 70184 KB Output is correct
2 Correct 3636 ms 70324 KB Output is correct
3 Correct 1779 ms 69960 KB Output is correct
4 Correct 3454 ms 70272 KB Output is correct
5 Correct 3081 ms 70516 KB Output is correct
6 Correct 3634 ms 70408 KB Output is correct
7 Correct 3580 ms 70100 KB Output is correct
8 Correct 3571 ms 70236 KB Output is correct
9 Correct 1663 ms 70008 KB Output is correct
10 Correct 2932 ms 70284 KB Output is correct
11 Correct 1638 ms 69880 KB Output is correct
12 Correct 2994 ms 70444 KB Output is correct
13 Correct 3346 ms 70264 KB Output is correct
14 Correct 3416 ms 70332 KB Output is correct
15 Correct 1757 ms 70008 KB Output is correct
16 Correct 3379 ms 70064 KB Output is correct
17 Correct 3027 ms 70136 KB Output is correct
18 Correct 3550 ms 70196 KB Output is correct
19 Correct 3569 ms 70264 KB Output is correct
20 Correct 3516 ms 70208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 376 KB Output is correct
2 Correct 90 ms 376 KB Output is correct
3 Correct 93 ms 380 KB Output is correct
4 Correct 89 ms 376 KB Output is correct
5 Correct 92 ms 376 KB Output is correct
6 Correct 91 ms 376 KB Output is correct
7 Correct 68 ms 376 KB Output is correct
8 Correct 71 ms 376 KB Output is correct
9 Correct 91 ms 504 KB Output is correct
10 Correct 120 ms 504 KB Output is correct
11 Correct 100 ms 376 KB Output is correct
12 Correct 110 ms 464 KB Output is correct
13 Correct 108 ms 504 KB Output is correct
14 Correct 126 ms 472 KB Output is correct
15 Correct 119 ms 504 KB Output is correct
16 Correct 38 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 3514 ms 70184 KB Output is correct
24 Correct 3636 ms 70324 KB Output is correct
25 Correct 1779 ms 69960 KB Output is correct
26 Correct 3454 ms 70272 KB Output is correct
27 Correct 3081 ms 70516 KB Output is correct
28 Correct 3634 ms 70408 KB Output is correct
29 Correct 3580 ms 70100 KB Output is correct
30 Correct 3571 ms 70236 KB Output is correct
31 Correct 1663 ms 70008 KB Output is correct
32 Correct 2932 ms 70284 KB Output is correct
33 Correct 1638 ms 69880 KB Output is correct
34 Correct 2994 ms 70444 KB Output is correct
35 Correct 3346 ms 70264 KB Output is correct
36 Correct 3416 ms 70332 KB Output is correct
37 Correct 1757 ms 70008 KB Output is correct
38 Correct 3379 ms 70064 KB Output is correct
39 Correct 3027 ms 70136 KB Output is correct
40 Correct 3550 ms 70196 KB Output is correct
41 Correct 3569 ms 70264 KB Output is correct
42 Correct 3516 ms 70208 KB Output is correct
43 Correct 2943 ms 5372 KB Output is correct
44 Correct 2963 ms 5504 KB Output is correct
45 Correct 2388 ms 5116 KB Output is correct
46 Correct 2968 ms 5196 KB Output is correct
47 Correct 3049 ms 4984 KB Output is correct
48 Correct 3712 ms 5088 KB Output is correct
49 Correct 3949 ms 5368 KB Output is correct
50 Correct 4025 ms 5112 KB Output is correct
51 Correct 3924 ms 5240 KB Output is correct
52 Correct 3631 ms 6824 KB Output is correct
53 Correct 3495 ms 6676 KB Output is correct
54 Correct 4168 ms 6860 KB Output is correct
55 Correct 4569 ms 6692 KB Output is correct
56 Correct 4565 ms 6608 KB Output is correct
57 Correct 4499 ms 6648 KB Output is correct
58 Correct 2810 ms 5796 KB Output is correct
59 Correct 2486 ms 5992 KB Output is correct
60 Correct 2928 ms 70396 KB Output is correct
61 Correct 3534 ms 70452 KB Output is correct
62 Correct 3459 ms 70396 KB Output is correct
63 Correct 3479 ms 70008 KB Output is correct
64 Correct 1725 ms 5032 KB Output is correct
65 Correct 1881 ms 37880 KB Output is correct
66 Correct 1890 ms 38268 KB Output is correct
67 Correct 3970 ms 41660 KB Output is correct
68 Correct 4249 ms 41660 KB Output is correct
69 Correct 4330 ms 41748 KB Output is correct
70 Correct 4299 ms 41908 KB Output is correct