Submission #134693

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

int N, Q, Sq=200;
int A[404040];
priority_queue<int> D[2020], P[2020];
priority_queue<int, vector<int>, greater<int>> C[2020];

int main(){
	scanf("%d %d", &N, &Q);
	for (int i=1; i<=N; i++){
		scanf("%d", &A[i]);
		D[i/Sq].push(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]) {
				while (!P[p].empty() && D[p].top() == P[p].top()) D[p].pop(), P[p].pop();
				P[p].push(A[i]), swap(A[i], X), D[p].push(A[i]);
			}
			for (p++; p<q; p++) {
				while (!P[p].empty() && D[p].top() == P[p].top()) D[p].pop(), P[p].pop();
				C[p].push(X), D[p].push(X);
				X = D[p].top(), D[p].pop();
			}
			for (int i=max(S,q*Sq); i<=T; i++) if (X < A[i]) {
				while (!P[q].empty() && D[q].top() == P[q].top()) D[q].pop(), P[q].pop();
				P[q].push(A[i]), swap(A[i], X), D[q].push(A[i]);
			}
		}
		else{
			for (int i=S; i<min((p+1)*Sq, N+1); i++) if (X < A[i]) {
				while (!P[p].empty() && D[p].top() == P[p].top()) D[p].pop(), P[p].pop();
				P[p].push(A[i]), swap(A[i], X), D[p].push(A[i]);
			}
			for (p++; p<=N/Sq; p++) {
				while (!P[p].empty() && D[p].top() == P[p].top()) D[p].pop(), P[p].pop();
				C[p].push(X), D[p].push(X);
				X = D[p].top(), D[p].pop();
			}
			for (p=0; p<q; p++) {
				while (!P[p].empty() && D[p].top() == P[p].top()) D[p].pop(), P[p].pop();
				C[p].push(X), D[p].push(X);
				X = D[p].top(), D[p].pop();
			}
			for (int i=max(1,q*Sq); i<=T; i++)  if (X < A[i]) {
				while (!P[q].empty() && D[q].top() == P[q].top()) D[q].pop(), P[q].pop();
				P[q].push(A[i]), swap(A[i], X), D[q].push(A[i]);}
			}
		}

		printf("%d\n", X);
	}
	return 0;
}
/*
7 100
13
90
35
60
38
64
83
1 4 33
7 1 14
4 5 47
1 7 82
6 1 93
6 5 56
*/

Compilation message

sushi.cpp: In function 'int main()':
sushi.cpp:62:18: error: 'X' was not declared in this scope
   printf("%d\n", X);
                  ^
sushi.cpp: At global scope:
sushi.cpp:64:2: error: expected unqualified-id before 'return'
  return 0;
  ^~~~~~
sushi.cpp:65:1: error: expected declaration before '}' token
 }
 ^
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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~