Submission #55896

# Submission time Handle Problem Language Result Execution time Memory
55896 2018-07-09T07:09:33 Z 윤교준(#1564) Sushi (JOI16_sushi) C++11
20 / 100
12000 ms 78712 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
const bool debug = 0;

const int MAXN = 400005;
const int MAXQ = 25005;
const int SQRN = 655;

struct BUK {
	vector<int> QV;
	priority_queue<int> PQ;
	int A[SQRN];
	int S, E, N;

	int cal(int s, int e, int x) {
		for(int i = s; i <= e; i++)
			if(x < A[i]) swap(A[i], x);
		return x;
	}

	int f(int p, int q, int x) {
		p = max(S, p); q = min(E, q);
		if(p > q) return x;
		if(PQ.top() <= x) return x;
		if(p <= S && E <= q) {
			QV.pb(x);
			int ret = PQ.top(); PQ.pop();
			PQ.push(x);
			return ret;
		}

		for(int v : QV) cal(0, N-1, v);
		QV.clear();

		int ret = cal(p-S, q-S, x);

		for(; !PQ.empty(); PQ.pop());
		for(int i = 0; i < N; i++)
			PQ.push(A[i]);

		return ret;
	}
} buk[SQRN]; int bukn;

int A[MAXN];
int B[MAXQ], C[MAXQ], D[MAXQ];

int N, Q;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> Q;
	for(int i = 1; i <= N; i++) cin >> A[i];
	for(int i = 1; i <= Q; i++) cin >> B[i] >> C[i] >> D[i];

	for(int i = 1, s, e;; i++) {
		s = (i-1)*SQRN + 1;
		e = min(N, i*SQRN);
		if(s > e) break;
		
		buk[i].S = s; buk[i].E = e;
		buk[i].N = e-s+1;
		for(int j = s; j <= e; j++) {
			buk[i].A[j-s] = A[j];
			buk[i].PQ.push(A[j]);
		}
		bukn = i;
	}

	if(debug) {
		printf("bukn=%d\n", bukn);
		for(int i = 1; i <= bukn; i++) {
			printf("%d buk : %d %d %d\n", i, buk[i].S, buk[i].E, buk[i].N);
			for(int j = 0; j < buk[i].N; j++) printf("%d ", buk[i].A[j]);
			puts("");
		}
	}

	for(int qi = 1, s, e, x; qi <= Q; qi++) {
		s = B[qi]; e = C[qi]; x = D[qi];

		if(s <= e) {
			for(int i = 1; i <= bukn; i++)
				x = buk[i].f(s, e, x);
		} else {
			for(int i = 1; i <= bukn; i++) {
				x = buk[i].f(s, N, x);
			}
			for(int i = 1; i <= bukn; i++)
				x = buk[i].f(1, e, x);
		}

		printf("%d\n", x);
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 132 ms 2176 KB Output is correct
2 Correct 128 ms 2276 KB Output is correct
3 Correct 126 ms 2368 KB Output is correct
4 Correct 137 ms 2420 KB Output is correct
5 Correct 137 ms 2420 KB Output is correct
6 Correct 144 ms 2512 KB Output is correct
7 Correct 40 ms 2512 KB Output is correct
8 Correct 29 ms 2528 KB Output is correct
9 Correct 154 ms 2536 KB Output is correct
10 Correct 121 ms 2536 KB Output is correct
11 Correct 174 ms 2536 KB Output is correct
12 Correct 165 ms 2732 KB Output is correct
13 Correct 177 ms 2732 KB Output is correct
14 Correct 95 ms 2732 KB Output is correct
15 Correct 91 ms 2732 KB Output is correct
16 Correct 124 ms 2732 KB Output is correct
17 Correct 4 ms 2732 KB Output is correct
18 Correct 3 ms 2732 KB Output is correct
19 Correct 4 ms 2732 KB Output is correct
20 Correct 3 ms 2732 KB Output is correct
21 Correct 4 ms 2732 KB Output is correct
22 Correct 3 ms 2732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1835 ms 78108 KB Output is correct
2 Correct 2020 ms 78108 KB Output is correct
3 Correct 129 ms 78108 KB Output is correct
4 Correct 1941 ms 78340 KB Output is correct
5 Correct 1671 ms 78340 KB Output is correct
6 Correct 1851 ms 78340 KB Output is correct
7 Correct 1826 ms 78340 KB Output is correct
8 Correct 1868 ms 78340 KB Output is correct
9 Correct 118 ms 78340 KB Output is correct
10 Correct 1357 ms 78340 KB Output is correct
11 Correct 134 ms 78340 KB Output is correct
12 Correct 1458 ms 78340 KB Output is correct
13 Correct 1770 ms 78340 KB Output is correct
14 Correct 1945 ms 78492 KB Output is correct
15 Correct 106 ms 78492 KB Output is correct
16 Correct 1901 ms 78712 KB Output is correct
17 Correct 1637 ms 78712 KB Output is correct
18 Correct 1859 ms 78712 KB Output is correct
19 Correct 1743 ms 78712 KB Output is correct
20 Correct 1650 ms 78712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 2176 KB Output is correct
2 Correct 128 ms 2276 KB Output is correct
3 Correct 126 ms 2368 KB Output is correct
4 Correct 137 ms 2420 KB Output is correct
5 Correct 137 ms 2420 KB Output is correct
6 Correct 144 ms 2512 KB Output is correct
7 Correct 40 ms 2512 KB Output is correct
8 Correct 29 ms 2528 KB Output is correct
9 Correct 154 ms 2536 KB Output is correct
10 Correct 121 ms 2536 KB Output is correct
11 Correct 174 ms 2536 KB Output is correct
12 Correct 165 ms 2732 KB Output is correct
13 Correct 177 ms 2732 KB Output is correct
14 Correct 95 ms 2732 KB Output is correct
15 Correct 91 ms 2732 KB Output is correct
16 Correct 124 ms 2732 KB Output is correct
17 Correct 4 ms 2732 KB Output is correct
18 Correct 3 ms 2732 KB Output is correct
19 Correct 4 ms 2732 KB Output is correct
20 Correct 3 ms 2732 KB Output is correct
21 Correct 4 ms 2732 KB Output is correct
22 Correct 3 ms 2732 KB Output is correct
23 Correct 1835 ms 78108 KB Output is correct
24 Correct 2020 ms 78108 KB Output is correct
25 Correct 129 ms 78108 KB Output is correct
26 Correct 1941 ms 78340 KB Output is correct
27 Correct 1671 ms 78340 KB Output is correct
28 Correct 1851 ms 78340 KB Output is correct
29 Correct 1826 ms 78340 KB Output is correct
30 Correct 1868 ms 78340 KB Output is correct
31 Correct 118 ms 78340 KB Output is correct
32 Correct 1357 ms 78340 KB Output is correct
33 Correct 134 ms 78340 KB Output is correct
34 Correct 1458 ms 78340 KB Output is correct
35 Correct 1770 ms 78340 KB Output is correct
36 Correct 1945 ms 78492 KB Output is correct
37 Correct 106 ms 78492 KB Output is correct
38 Correct 1901 ms 78712 KB Output is correct
39 Correct 1637 ms 78712 KB Output is correct
40 Correct 1859 ms 78712 KB Output is correct
41 Correct 1743 ms 78712 KB Output is correct
42 Correct 1650 ms 78712 KB Output is correct
43 Correct 2172 ms 78712 KB Output is correct
44 Correct 2351 ms 78712 KB Output is correct
45 Correct 521 ms 78712 KB Output is correct
46 Correct 2169 ms 78712 KB Output is correct
47 Correct 2201 ms 78712 KB Output is correct
48 Correct 6592 ms 78712 KB Output is correct
49 Execution timed out 12071 ms 78712 KB Time limit exceeded
50 Halted 0 ms 0 KB -