Submission #134875

# Submission time Handle Problem Language Result Execution time Memory
134875 2019-07-23T11:10:32 Z imyujin Sushi (JOI16_sushi) C++14
100 / 100
6877 ms 79316 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 410005;
const int BUCKET = 633;

int X[MAXN], S[MAXN], T[MAXN], P[MAXN];
priority_queue<int> d[BUCKET];
priority_queue<int, vector<int>, greater<int> > q[BUCKET];

void updbuc(int k) {
	for(int i = k * BUCKET; i < (k + 1) * BUCKET; i++) {
		q[k].push(X[i]);
		X[i] = q[k].top();
		q[k].pop();
	}
	while(!q[k].empty()) q[k].pop();
}

int updnai(int k, int s, int e, int x) {
	for(int i = s; i <= e; i++) if(X[i] > x) swap(X[i], x);
	while(!d[k].empty()) d[k].pop();
	for(int i = k * BUCKET; i < (k + 1) * BUCKET; i++) d[k].push(X[i]);
	return x;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int N, Q;

	cin >> N >> Q;
	for(int i = 0; i < N; i++) cin >> X[i];
	for(int i = 0; i < Q; i++) cin >> S[i] >> T[i] >> P[i];

	for(int i = 0; i < BUCKET * BUCKET; i++) d[i / BUCKET].push(X[i]);
	for(int i = 0; i < Q; i++) {
		S[i]--;
		T[i]--;
		int ks = S[i] / BUCKET, kt = T[i] / BUCKET;
		updbuc(ks);
		if(ks == kt && S[i] <= T[i]) cout << updnai(ks, S[i], T[i], P[i]) << "\n";
		else {
			P[i] = updnai(ks, S[i], (ks + 1) * BUCKET - 1, P[i]);
			for(int j = (ks + 1) % BUCKET; j != kt; j = (j + 1) % BUCKET) {
				q[j].push(P[i]);
				d[j].push(P[i]);
				P[i] = d[j].top();
				d[j].pop();
			}
			updbuc(kt);
			cout << updnai(kt, kt * BUCKET, T[i], P[i]) << "\n";
		}
		//for(int i = 0; i < N; i++) printf("%d ", X[i]);
		//printf("\n");
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 293 ms 8284 KB Output is correct
2 Correct 289 ms 5884 KB Output is correct
3 Correct 293 ms 8184 KB Output is correct
4 Correct 285 ms 5624 KB Output is correct
5 Correct 287 ms 5624 KB Output is correct
6 Correct 292 ms 8056 KB Output is correct
7 Correct 164 ms 5624 KB Output is correct
8 Correct 168 ms 8184 KB Output is correct
9 Correct 293 ms 5624 KB Output is correct
10 Correct 294 ms 5752 KB Output is correct
11 Correct 298 ms 5624 KB Output is correct
12 Correct 292 ms 5624 KB Output is correct
13 Correct 304 ms 8284 KB Output is correct
14 Correct 373 ms 8184 KB Output is correct
15 Correct 371 ms 8372 KB Output is correct
16 Correct 123 ms 3192 KB Output is correct
17 Correct 9 ms 2936 KB Output is correct
18 Correct 10 ms 2936 KB Output is correct
19 Correct 9 ms 2936 KB Output is correct
20 Correct 9 ms 2936 KB Output is correct
21 Correct 10 ms 2936 KB Output is correct
22 Correct 10 ms 2948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6044 ms 77828 KB Output is correct
2 Correct 6063 ms 77680 KB Output is correct
3 Correct 3014 ms 77416 KB Output is correct
4 Correct 6012 ms 77712 KB Output is correct
5 Correct 5220 ms 77784 KB Output is correct
6 Correct 6101 ms 77564 KB Output is correct
7 Correct 6087 ms 77844 KB Output is correct
8 Correct 6037 ms 77572 KB Output is correct
9 Correct 2468 ms 77504 KB Output is correct
10 Correct 5199 ms 77724 KB Output is correct
11 Correct 2363 ms 77560 KB Output is correct
12 Correct 5177 ms 77696 KB Output is correct
13 Correct 6062 ms 77616 KB Output is correct
14 Correct 6104 ms 77688 KB Output is correct
15 Correct 2987 ms 77532 KB Output is correct
16 Correct 6081 ms 77868 KB Output is correct
17 Correct 5186 ms 77800 KB Output is correct
18 Correct 6108 ms 77680 KB Output is correct
19 Correct 6121 ms 77728 KB Output is correct
20 Correct 6002 ms 77716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 8284 KB Output is correct
2 Correct 289 ms 5884 KB Output is correct
3 Correct 293 ms 8184 KB Output is correct
4 Correct 285 ms 5624 KB Output is correct
5 Correct 287 ms 5624 KB Output is correct
6 Correct 292 ms 8056 KB Output is correct
7 Correct 164 ms 5624 KB Output is correct
8 Correct 168 ms 8184 KB Output is correct
9 Correct 293 ms 5624 KB Output is correct
10 Correct 294 ms 5752 KB Output is correct
11 Correct 298 ms 5624 KB Output is correct
12 Correct 292 ms 5624 KB Output is correct
13 Correct 304 ms 8284 KB Output is correct
14 Correct 373 ms 8184 KB Output is correct
15 Correct 371 ms 8372 KB Output is correct
16 Correct 123 ms 3192 KB Output is correct
17 Correct 9 ms 2936 KB Output is correct
18 Correct 10 ms 2936 KB Output is correct
19 Correct 9 ms 2936 KB Output is correct
20 Correct 9 ms 2936 KB Output is correct
21 Correct 10 ms 2936 KB Output is correct
22 Correct 10 ms 2948 KB Output is correct
23 Correct 6044 ms 77828 KB Output is correct
24 Correct 6063 ms 77680 KB Output is correct
25 Correct 3014 ms 77416 KB Output is correct
26 Correct 6012 ms 77712 KB Output is correct
27 Correct 5220 ms 77784 KB Output is correct
28 Correct 6101 ms 77564 KB Output is correct
29 Correct 6087 ms 77844 KB Output is correct
30 Correct 6037 ms 77572 KB Output is correct
31 Correct 2468 ms 77504 KB Output is correct
32 Correct 5199 ms 77724 KB Output is correct
33 Correct 2363 ms 77560 KB Output is correct
34 Correct 5177 ms 77696 KB Output is correct
35 Correct 6062 ms 77616 KB Output is correct
36 Correct 6104 ms 77688 KB Output is correct
37 Correct 2987 ms 77532 KB Output is correct
38 Correct 6081 ms 77868 KB Output is correct
39 Correct 5186 ms 77800 KB Output is correct
40 Correct 6108 ms 77680 KB Output is correct
41 Correct 6121 ms 77728 KB Output is correct
42 Correct 6002 ms 77716 KB Output is correct
43 Correct 5229 ms 9876 KB Output is correct
44 Correct 5197 ms 9668 KB Output is correct
45 Correct 3321 ms 9436 KB Output is correct
46 Correct 5191 ms 9652 KB Output is correct
47 Correct 5192 ms 9756 KB Output is correct
48 Correct 5604 ms 9596 KB Output is correct
49 Correct 5867 ms 9864 KB Output is correct
50 Correct 5884 ms 9724 KB Output is correct
51 Correct 5879 ms 9572 KB Output is correct
52 Correct 6526 ms 16744 KB Output is correct
53 Correct 6310 ms 15972 KB Output is correct
54 Correct 6632 ms 16120 KB Output is correct
55 Correct 6877 ms 16040 KB Output is correct
56 Correct 6841 ms 16208 KB Output is correct
57 Correct 6848 ms 16040 KB Output is correct
58 Correct 5132 ms 11580 KB Output is correct
59 Correct 5242 ms 11624 KB Output is correct
60 Correct 5170 ms 78920 KB Output is correct
61 Correct 6002 ms 79224 KB Output is correct
62 Correct 5971 ms 79072 KB Output is correct
63 Correct 5936 ms 79316 KB Output is correct
64 Correct 2219 ms 9056 KB Output is correct
65 Correct 3488 ms 43588 KB Output is correct
66 Correct 3508 ms 43500 KB Output is correct
67 Correct 5653 ms 65352 KB Output is correct
68 Correct 6128 ms 65492 KB Output is correct
69 Correct 6134 ms 65400 KB Output is correct
70 Correct 6097 ms 65460 KB Output is correct