Submission #134667

# Submission time Handle Problem Language Result Execution time Memory
134667 2019-07-23T07:03:57 Z 송준혁(#3242) Sushi (JOI16_sushi) C++14
5 / 100
12000 ms 79504 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N, Q, Sq=800;
int A[404040];
multiset<int> D[600];
priority_queue<int, vector<int>, greater<int>> C[600];

int main(){
	scanf("%d %d", &N, &Q);
	for (int i=1; i<=N; i++){
		scanf("%d", &A[i]);
		D[i/Sq].insert(A[i]);
	}
	while (Q--){
		int S, T, X;
		scanf("%d %d %d", &S, &T, &X);
		int p = S/Sq, q = T/Sq;
		for (int i=max(1,p*Sq); i<min((p+1)*Sq, N+1); i++) C[p].push(A[i]), A[i] = C[p].top(), C[p].pop();
		while (!C[p].empty()) C[p].pop();
		for (int i=max(1,q*Sq); i<min((q+1)*Sq, N+1); i++) C[q].push(A[i]), A[i] = C[q].top(), C[q].pop();
		while (!C[q].empty()) C[q].pop();

		if (S <= T){
			for (int i=S; i<min((p+1)*Sq, T+1); i++) if (X < A[i]) {
				D[p].erase(D[p].lower_bound(A[i]));
				swap(A[i], X);
				D[p].insert(A[i]);
			}
			for (p++; p<q; p++) C[p].push(X), D[p].insert(X), X = *--D[p].end(), D[p].erase(--D[p].end());
			for (int i=max(S,q*Sq); i<=T; i++) if (X < A[i]) {
				D[q].erase(D[q].lower_bound(A[i]));
				swap(A[i], X);
				D[q].insert(A[i]);
			}
		}
		else{
			for (int i=S; i<min((p+1)*Sq, N+1); i++) if (X < A[i]) {
				D[p].erase(D[p].lower_bound(A[i]));
				swap(A[i], X);
				D[p].insert(A[i]);
			}
			for (p++; p<=N/Sq; p++) C[p].push(X), D[p].insert(X), X = *--D[p].end(), D[p].erase(--D[p].end());
			for (p=0; p<q; p++) C[p].push(X), D[p].insert(X), X = *--D[p].end(), D[p].erase(--D[p].end());
			for (int i=max(1,q*Sq); i<=T; i++) if (X < A[i]) {
				D[q].erase(D[q].lower_bound(A[i]));
				swap(A[i], X);
				D[q].insert(A[i]);
			}
		}

		printf("%d\n", X);
	}
	return 0;
}

Compilation message

sushi.cpp: In function 'int main()':
sushi.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~~
sushi.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &A[i]);
   ~~~~~^~~~~~~~~~~~~
sushi.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &S, &T, &X);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 632 KB Output is correct
2 Correct 35 ms 376 KB Output is correct
3 Correct 36 ms 504 KB Output is correct
4 Correct 36 ms 632 KB Output is correct
5 Correct 35 ms 504 KB Output is correct
6 Correct 35 ms 504 KB Output is correct
7 Correct 31 ms 504 KB Output is correct
8 Correct 32 ms 504 KB Output is correct
9 Correct 38 ms 632 KB Output is correct
10 Correct 35 ms 504 KB Output is correct
11 Correct 105 ms 504 KB Output is correct
12 Correct 104 ms 584 KB Output is correct
13 Correct 94 ms 744 KB Output is correct
14 Correct 41 ms 504 KB Output is correct
15 Correct 42 ms 572 KB Output is correct
16 Correct 24 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10020 ms 79504 KB Output is correct
2 Correct 10064 ms 79324 KB Output is correct
3 Correct 6887 ms 78684 KB Output is correct
4 Correct 10284 ms 79408 KB Output is correct
5 Correct 11802 ms 79428 KB Output is correct
6 Execution timed out 12052 ms 74056 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 632 KB Output is correct
2 Correct 35 ms 376 KB Output is correct
3 Correct 36 ms 504 KB Output is correct
4 Correct 36 ms 632 KB Output is correct
5 Correct 35 ms 504 KB Output is correct
6 Correct 35 ms 504 KB Output is correct
7 Correct 31 ms 504 KB Output is correct
8 Correct 32 ms 504 KB Output is correct
9 Correct 38 ms 632 KB Output is correct
10 Correct 35 ms 504 KB Output is correct
11 Correct 105 ms 504 KB Output is correct
12 Correct 104 ms 584 KB Output is correct
13 Correct 94 ms 744 KB Output is correct
14 Correct 41 ms 504 KB Output is correct
15 Correct 42 ms 572 KB Output is correct
16 Correct 24 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 10020 ms 79504 KB Output is correct
24 Correct 10064 ms 79324 KB Output is correct
25 Correct 6887 ms 78684 KB Output is correct
26 Correct 10284 ms 79408 KB Output is correct
27 Correct 11802 ms 79428 KB Output is correct
28 Execution timed out 12052 ms 74056 KB Time limit exceeded
29 Halted 0 ms 0 KB -