답안 #55114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55114 2018-07-06T05:15:06 Z ainta(#1558) Sushi (JOI16_sushi) C++11
5 / 100
9235 ms 263168 KB
#include<cstdio>
#include<algorithm>
#include<queue>
#define BB 3
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;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	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;
}
/*
#include<cstdio>
#include<algorithm>
using namespace std;
int n = 100, Q = 200;
int main() {
	freopen("input.txt", "w", stdout);
	srand(1879);
	int i;
	printf("%d %d\n", n, Q);
	for (i = 1; i <= n; i++) {
		printf("%d\n", rand() % 100 + 1);
	}
	for (i = 1; i <= Q; i++) {
		printf("%d %d %d\n", rand() % n + 1, rand() % n + 1, rand() % 100 + 1);
	}
}*/
/*
#include<cstdio>
#include<algorithm>
#include<queue>
#define BB 12
using namespace std;
int n, Q;
struct point {
	int P[1 << BB], SZ;
	int U[1 << BB], UC;
	priority_queue<int>PQ;
	void init() {
		int i;
		for (i = UC - 1; i >= 0; i--) {
			P[U[i]] = PQ.top();
			PQ.pop();
		}
	}
	void Make() {
		int i, Mx = -1;
		UC = 0;
		while (!PQ.empty())PQ.pop();
		for (i = 0; i < SZ; i++) {
			if (Mx < P[i]) {
				Mx = P[i];
				U[UC++] = i;
				PQ.push(P[i]);
			}
		}
	}
	int Go(int 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;
	freopen("input.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
	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:63: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:65: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:70: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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 5372 KB Output is correct
2 Correct 23 ms 5476 KB Output is correct
3 Correct 27 ms 5696 KB Output is correct
4 Correct 31 ms 5696 KB Output is correct
5 Correct 32 ms 5696 KB Output is correct
6 Correct 27 ms 5696 KB Output is correct
7 Correct 25 ms 5696 KB Output is correct
8 Correct 26 ms 5696 KB Output is correct
9 Correct 25 ms 5696 KB Output is correct
10 Correct 24 ms 5696 KB Output is correct
11 Correct 24 ms 5780 KB Output is correct
12 Correct 24 ms 5780 KB Output is correct
13 Correct 38 ms 5780 KB Output is correct
14 Correct 55 ms 6368 KB Output is correct
15 Correct 36 ms 6368 KB Output is correct
16 Correct 8 ms 6368 KB Output is correct
17 Correct 5 ms 6368 KB Output is correct
18 Correct 8 ms 6368 KB Output is correct
19 Correct 5 ms 6368 KB Output is correct
20 Correct 5 ms 6368 KB Output is correct
21 Correct 5 ms 6368 KB Output is correct
22 Correct 6 ms 6368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 9235 ms 263168 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 5372 KB Output is correct
2 Correct 23 ms 5476 KB Output is correct
3 Correct 27 ms 5696 KB Output is correct
4 Correct 31 ms 5696 KB Output is correct
5 Correct 32 ms 5696 KB Output is correct
6 Correct 27 ms 5696 KB Output is correct
7 Correct 25 ms 5696 KB Output is correct
8 Correct 26 ms 5696 KB Output is correct
9 Correct 25 ms 5696 KB Output is correct
10 Correct 24 ms 5696 KB Output is correct
11 Correct 24 ms 5780 KB Output is correct
12 Correct 24 ms 5780 KB Output is correct
13 Correct 38 ms 5780 KB Output is correct
14 Correct 55 ms 6368 KB Output is correct
15 Correct 36 ms 6368 KB Output is correct
16 Correct 8 ms 6368 KB Output is correct
17 Correct 5 ms 6368 KB Output is correct
18 Correct 8 ms 6368 KB Output is correct
19 Correct 5 ms 6368 KB Output is correct
20 Correct 5 ms 6368 KB Output is correct
21 Correct 5 ms 6368 KB Output is correct
22 Correct 6 ms 6368 KB Output is correct
23 Execution timed out 9235 ms 263168 KB Time limit exceeded (wall clock)
24 Halted 0 ms 0 KB -