Submission #55122

# Submission time Handle Problem Language Result Execution time Memory
55122 2018-07-06T05:29:00 Z ainta Sushi (JOI16_sushi) C++17
100 / 100
7090 ms 95684 KB
#include<cstdio>
#include<algorithm>
#include<queue>
#define BB 9
using namespace std;
int n, Q;
struct point {
	int P[1 << BB], SZ;
	vector<int>U;
	priority_queue<int>PQ;
	void Make() {
		int i;
		while (!PQ.empty())PQ.pop();
		for (i = 0; i < SZ; i++) {
			PQ.push(P[i]);
		}
	}
	void init() {
		priority_queue<int>PP;
		for (auto &t : U) {
			PP.push(-t);
		}
		int i;
		for (i = 0; i < SZ; i++) {
			PP.push(-P[i]);
			P[i] = -PP.top();
			PP.pop();
		}
		U.clear();
	}
	int Go(int x) {
		U.push_back(x);
		PQ.push(x);
		int ret = PQ.top();
		PQ.pop();
		return ret;
	}
}w[(400000 >> BB) + 2];
int Do(int b, int e, int x) {
	for (int i = (b >> BB); i <= (e >> BB); i++) {
		int bb = (i << BB), ee = min(((i + 1) << BB) - 1, n - 1);
		if (b <= bb && ee <= e) {
			x = w[i].Go(x);
		}
		else {
			w[i].init();
			bb = max(b, bb)&((1 << BB) - 1);
			ee = min(e, ee)&((1 << BB) - 1);
			for (int j = bb; j <= ee; j++) {
				if (w[i].P[j] > x) {
					swap(w[i].P[j], x);
				}
			}
			w[i].Make();
		}
	}
	return x;
}
int main() {
	int i, b, e, c;
	scanf("%d%d", &n, &Q);
	for (i = 0; i < n; i++) {
		scanf("%d", &w[i >> BB].P[i&((1 << BB) - 1)]);
		w[i >> BB].SZ++;
	}
	for (i = 0; i <= ((n - 1) >> BB); i++)w[i].Make();
	while (Q--) {
		scanf("%d%d%d", &b, &e, &c);
		b--, e--;
		if (b > e) {
			printf("%d\n", Do(0, e, Do(b, n - 1, c)));
		}
		else {
			printf("%d\n", Do(b, e, c));
		}
	}
	return 0;
}

Compilation message

telegraph.cpp: In function 'int main()':
telegraph.cpp:61: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:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &w[i >> BB].P[i&((1 << BB) - 1)]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
telegraph.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &b, &e, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 195 ms 1972 KB Output is correct
2 Correct 221 ms 2156 KB Output is correct
3 Correct 210 ms 2156 KB Output is correct
4 Correct 174 ms 2156 KB Output is correct
5 Correct 176 ms 2168 KB Output is correct
6 Correct 204 ms 2464 KB Output is correct
7 Correct 90 ms 2464 KB Output is correct
8 Correct 94 ms 2464 KB Output is correct
9 Correct 179 ms 2464 KB Output is correct
10 Correct 209 ms 2464 KB Output is correct
11 Correct 203 ms 2464 KB Output is correct
12 Correct 175 ms 2464 KB Output is correct
13 Correct 210 ms 2464 KB Output is correct
14 Correct 212 ms 2464 KB Output is correct
15 Correct 197 ms 2464 KB Output is correct
16 Correct 91 ms 2464 KB Output is correct
17 Correct 3 ms 2464 KB Output is correct
18 Correct 3 ms 2464 KB Output is correct
19 Correct 3 ms 2464 KB Output is correct
20 Correct 3 ms 2464 KB Output is correct
21 Correct 4 ms 2464 KB Output is correct
22 Correct 3 ms 2464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2822 ms 95464 KB Output is correct
2 Correct 2964 ms 95464 KB Output is correct
3 Correct 2272 ms 95464 KB Output is correct
4 Correct 2860 ms 95480 KB Output is correct
5 Correct 2780 ms 95488 KB Output is correct
6 Correct 2644 ms 95504 KB Output is correct
7 Correct 2734 ms 95684 KB Output is correct
8 Correct 2767 ms 95684 KB Output is correct
9 Correct 2208 ms 95684 KB Output is correct
10 Correct 2855 ms 95684 KB Output is correct
11 Correct 2227 ms 95684 KB Output is correct
12 Correct 2613 ms 95684 KB Output is correct
13 Correct 3393 ms 95684 KB Output is correct
14 Correct 2936 ms 95684 KB Output is correct
15 Correct 2144 ms 95684 KB Output is correct
16 Correct 3200 ms 95684 KB Output is correct
17 Correct 2138 ms 95684 KB Output is correct
18 Correct 3013 ms 95684 KB Output is correct
19 Correct 3224 ms 95684 KB Output is correct
20 Correct 2808 ms 95684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 1972 KB Output is correct
2 Correct 221 ms 2156 KB Output is correct
3 Correct 210 ms 2156 KB Output is correct
4 Correct 174 ms 2156 KB Output is correct
5 Correct 176 ms 2168 KB Output is correct
6 Correct 204 ms 2464 KB Output is correct
7 Correct 90 ms 2464 KB Output is correct
8 Correct 94 ms 2464 KB Output is correct
9 Correct 179 ms 2464 KB Output is correct
10 Correct 209 ms 2464 KB Output is correct
11 Correct 203 ms 2464 KB Output is correct
12 Correct 175 ms 2464 KB Output is correct
13 Correct 210 ms 2464 KB Output is correct
14 Correct 212 ms 2464 KB Output is correct
15 Correct 197 ms 2464 KB Output is correct
16 Correct 91 ms 2464 KB Output is correct
17 Correct 3 ms 2464 KB Output is correct
18 Correct 3 ms 2464 KB Output is correct
19 Correct 3 ms 2464 KB Output is correct
20 Correct 3 ms 2464 KB Output is correct
21 Correct 4 ms 2464 KB Output is correct
22 Correct 3 ms 2464 KB Output is correct
23 Correct 2822 ms 95464 KB Output is correct
24 Correct 2964 ms 95464 KB Output is correct
25 Correct 2272 ms 95464 KB Output is correct
26 Correct 2860 ms 95480 KB Output is correct
27 Correct 2780 ms 95488 KB Output is correct
28 Correct 2644 ms 95504 KB Output is correct
29 Correct 2734 ms 95684 KB Output is correct
30 Correct 2767 ms 95684 KB Output is correct
31 Correct 2208 ms 95684 KB Output is correct
32 Correct 2855 ms 95684 KB Output is correct
33 Correct 2227 ms 95684 KB Output is correct
34 Correct 2613 ms 95684 KB Output is correct
35 Correct 3393 ms 95684 KB Output is correct
36 Correct 2936 ms 95684 KB Output is correct
37 Correct 2144 ms 95684 KB Output is correct
38 Correct 3200 ms 95684 KB Output is correct
39 Correct 2138 ms 95684 KB Output is correct
40 Correct 3013 ms 95684 KB Output is correct
41 Correct 3224 ms 95684 KB Output is correct
42 Correct 2808 ms 95684 KB Output is correct
43 Correct 4862 ms 95684 KB Output is correct
44 Correct 5024 ms 95684 KB Output is correct
45 Correct 3432 ms 95684 KB Output is correct
46 Correct 4951 ms 95684 KB Output is correct
47 Correct 5143 ms 95684 KB Output is correct
48 Correct 4944 ms 95684 KB Output is correct
49 Correct 5449 ms 95684 KB Output is correct
50 Correct 5247 ms 95684 KB Output is correct
51 Correct 5311 ms 95684 KB Output is correct
52 Correct 5617 ms 95684 KB Output is correct
53 Correct 5544 ms 95684 KB Output is correct
54 Correct 5811 ms 95684 KB Output is correct
55 Correct 6368 ms 95684 KB Output is correct
56 Correct 7090 ms 95684 KB Output is correct
57 Correct 6439 ms 95684 KB Output is correct
58 Correct 4010 ms 95684 KB Output is correct
59 Correct 3789 ms 95684 KB Output is correct
60 Correct 4153 ms 95684 KB Output is correct
61 Correct 5777 ms 95684 KB Output is correct
62 Correct 6141 ms 95684 KB Output is correct
63 Correct 5212 ms 95684 KB Output is correct
64 Correct 2845 ms 95684 KB Output is correct
65 Correct 3094 ms 95684 KB Output is correct
66 Correct 2866 ms 95684 KB Output is correct
67 Correct 4685 ms 95684 KB Output is correct
68 Correct 5404 ms 95684 KB Output is correct
69 Correct 5181 ms 95684 KB Output is correct
70 Correct 5775 ms 95684 KB Output is correct