Submission #55120

# Submission time Handle Problem Language Result Execution time Memory
55120 2018-07-06T05:24:33 Z ainta Sushi (JOI16_sushi) C++17
100 / 100
9720 ms 50972 KB
#include<cstdio>
#include<algorithm>
#include<queue>
#define BB 10
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 388 ms 2040 KB Output is correct
2 Correct 375 ms 2044 KB Output is correct
3 Correct 386 ms 2072 KB Output is correct
4 Correct 391 ms 2548 KB Output is correct
5 Correct 410 ms 2548 KB Output is correct
6 Correct 379 ms 2548 KB Output is correct
7 Correct 156 ms 2548 KB Output is correct
8 Correct 189 ms 2548 KB Output is correct
9 Correct 376 ms 2548 KB Output is correct
10 Correct 412 ms 2548 KB Output is correct
11 Correct 343 ms 2548 KB Output is correct
12 Correct 393 ms 2548 KB Output is correct
13 Correct 381 ms 2548 KB Output is correct
14 Correct 389 ms 2548 KB Output is correct
15 Correct 398 ms 2548 KB Output is correct
16 Correct 204 ms 2548 KB Output is correct
17 Correct 4 ms 2548 KB Output is correct
18 Correct 3 ms 2548 KB Output is correct
19 Correct 3 ms 2548 KB Output is correct
20 Correct 3 ms 2548 KB Output is correct
21 Correct 3 ms 2548 KB Output is correct
22 Correct 3 ms 2548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1890 ms 50820 KB Output is correct
2 Correct 1681 ms 50820 KB Output is correct
3 Correct 1256 ms 50820 KB Output is correct
4 Correct 1699 ms 50860 KB Output is correct
5 Correct 1484 ms 50860 KB Output is correct
6 Correct 1699 ms 50860 KB Output is correct
7 Correct 1613 ms 50860 KB Output is correct
8 Correct 1578 ms 50860 KB Output is correct
9 Correct 1097 ms 50860 KB Output is correct
10 Correct 1408 ms 50860 KB Output is correct
11 Correct 1053 ms 50860 KB Output is correct
12 Correct 1354 ms 50888 KB Output is correct
13 Correct 1707 ms 50888 KB Output is correct
14 Correct 1673 ms 50888 KB Output is correct
15 Correct 1216 ms 50888 KB Output is correct
16 Correct 1902 ms 50900 KB Output is correct
17 Correct 1269 ms 50908 KB Output is correct
18 Correct 1492 ms 50972 KB Output is correct
19 Correct 1529 ms 50972 KB Output is correct
20 Correct 1565 ms 50972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 388 ms 2040 KB Output is correct
2 Correct 375 ms 2044 KB Output is correct
3 Correct 386 ms 2072 KB Output is correct
4 Correct 391 ms 2548 KB Output is correct
5 Correct 410 ms 2548 KB Output is correct
6 Correct 379 ms 2548 KB Output is correct
7 Correct 156 ms 2548 KB Output is correct
8 Correct 189 ms 2548 KB Output is correct
9 Correct 376 ms 2548 KB Output is correct
10 Correct 412 ms 2548 KB Output is correct
11 Correct 343 ms 2548 KB Output is correct
12 Correct 393 ms 2548 KB Output is correct
13 Correct 381 ms 2548 KB Output is correct
14 Correct 389 ms 2548 KB Output is correct
15 Correct 398 ms 2548 KB Output is correct
16 Correct 204 ms 2548 KB Output is correct
17 Correct 4 ms 2548 KB Output is correct
18 Correct 3 ms 2548 KB Output is correct
19 Correct 3 ms 2548 KB Output is correct
20 Correct 3 ms 2548 KB Output is correct
21 Correct 3 ms 2548 KB Output is correct
22 Correct 3 ms 2548 KB Output is correct
23 Correct 1890 ms 50820 KB Output is correct
24 Correct 1681 ms 50820 KB Output is correct
25 Correct 1256 ms 50820 KB Output is correct
26 Correct 1699 ms 50860 KB Output is correct
27 Correct 1484 ms 50860 KB Output is correct
28 Correct 1699 ms 50860 KB Output is correct
29 Correct 1613 ms 50860 KB Output is correct
30 Correct 1578 ms 50860 KB Output is correct
31 Correct 1097 ms 50860 KB Output is correct
32 Correct 1408 ms 50860 KB Output is correct
33 Correct 1053 ms 50860 KB Output is correct
34 Correct 1354 ms 50888 KB Output is correct
35 Correct 1707 ms 50888 KB Output is correct
36 Correct 1673 ms 50888 KB Output is correct
37 Correct 1216 ms 50888 KB Output is correct
38 Correct 1902 ms 50900 KB Output is correct
39 Correct 1269 ms 50908 KB Output is correct
40 Correct 1492 ms 50972 KB Output is correct
41 Correct 1529 ms 50972 KB Output is correct
42 Correct 1565 ms 50972 KB Output is correct
43 Correct 7937 ms 50972 KB Output is correct
44 Correct 7679 ms 50972 KB Output is correct
45 Correct 5285 ms 50972 KB Output is correct
46 Correct 7918 ms 50972 KB Output is correct
47 Correct 7650 ms 50972 KB Output is correct
48 Correct 7796 ms 50972 KB Output is correct
49 Correct 8090 ms 50972 KB Output is correct
50 Correct 9720 ms 50972 KB Output is correct
51 Correct 8129 ms 50972 KB Output is correct
52 Correct 7636 ms 50972 KB Output is correct
53 Correct 7679 ms 50972 KB Output is correct
54 Correct 7869 ms 50972 KB Output is correct
55 Correct 8738 ms 50972 KB Output is correct
56 Correct 8507 ms 50972 KB Output is correct
57 Correct 8569 ms 50972 KB Output is correct
58 Correct 4458 ms 50972 KB Output is correct
59 Correct 4913 ms 50972 KB Output is correct
60 Correct 5282 ms 50972 KB Output is correct
61 Correct 5633 ms 50972 KB Output is correct
62 Correct 5747 ms 50972 KB Output is correct
63 Correct 5944 ms 50972 KB Output is correct
64 Correct 3322 ms 50972 KB Output is correct
65 Correct 3988 ms 50972 KB Output is correct
66 Correct 3898 ms 50972 KB Output is correct
67 Correct 6276 ms 50972 KB Output is correct
68 Correct 6686 ms 50972 KB Output is correct
69 Correct 6631 ms 50972 KB Output is correct
70 Correct 6525 ms 50972 KB Output is correct