| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 191494 | dndhk | Sushi (JOI16_sushi) | C++14 | 7555 ms | 10764 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 400000;
const int SQ = 700;
int N, Q;
int arr[MAX_N+1];
int g[MAX_N+1];
priority_queue<int> pq1[SQ+1], pq2;
int solve(int gn, int s, int e, int k){
	int x = gn*SQ+1, y = min((gn+1)*SQ, N);
	//cout<<s<<" "<<e<<" "<<k<<" "<<endl;
	//cout<<x<<" "<<y<<endl;
	if(s<=x && y<=e){
		pq1[gn].push(k);
		k = pq1[gn].top();
		pq1[gn].pop();
		return k;
	}else{
		for(int i=y; i>=x; i--){
			while(!pq1[gn].empty() && !pq2.empty() && pq1[gn].top()==pq2.top()){
				pq1[gn].pop();
				pq2.pop();
			}
			//cout<<i<<" "<<pq1[gn].top()<<" "<<arr[i]<<endl;
			if(arr[i]>pq1[gn].top()){
				arr[i] = pq1[gn].top();
				pq1[gn].pop();
			}else{
				pq2.push(arr[i]);
			}
		}
		while(!pq1[gn].empty())	pq1[gn].pop();
		while(!pq2.empty())	pq2.pop();
		for(int i=x; i<=y; i++){
			if(s<=i && i<=e){
				if(k<arr[i]){
					int tmp = k;
					k = arr[i];
					arr[i] = tmp;
				}
			}
			pq1[gn].push(arr[i]);
		}
		return k;
	}
}
int main(){
	scanf("%d%d", &N, &Q);
	for(int i=1; i<=N; i++){
		scanf("%d", &arr[i]);
		g[i] = (i-1)/SQ;
		pq1[g[i]].push(arr[i]);
	}
	for(int i=1; i<=Q; i++){
		int s, e, k;
		scanf("%d%d%d", &s, &e, &k);
		if(s<=e){
			int n = g[s];
			while(n<=g[e]){
				k = solve(n, s, e, k);
				n++;
			}
		}else{
			int n = g[s];
			while(n<=g[N]){
				k = solve(n, s, N, k);
				n++;
			}
			n = 0;
			while(n<=g[e]){
				k = solve(n, 1, e, k);
				n++;
			}
		}
		printf("%d\n", k);
	}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
