Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

放爷算法6907ms,因为一个地方王记判断队列是否为空re了好几次。。。

Posted by KatrineYang at 2016-07-17 10:18:23 on Problem 2823 and last updated at 2016-07-17 10:19:07
#include <iostream>
#include <deque>
#include <stdio.h>

using namespace std;



int data[1000010];

deque<int> fangyeMin, fangyeMax;

int main() {

	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++){
		scanf("%d", &data[i]);
	}
	for(int i = 0; i < k-1; i++){
		while(!fangyeMin.empty() && data[fangyeMin.back()] >= data[i]){
				fangyeMin.pop_back();
		}
		fangyeMin.push_back(i);
	}
	for(int i = k-1; i < n; i++){
		if(!fangyeMin.empty() && fangyeMin.front() == i - k) fangyeMin.pop_front();
		while(!fangyeMin.empty() && data[fangyeMin.back()] >= data[i]){
			fangyeMin.pop_back();
		}
		fangyeMin.push_back(i);
		printf("%d ", data[fangyeMin.front()]);
	}
	printf("\n");
	for(int i = 0; i < k-1; i++){
		while(!fangyeMax.empty() && data[fangyeMax.back()] <= data[i]){
				fangyeMax.pop_back();
		}
		fangyeMax.push_back(i);
	}
	for(int i = k-1; i < n; i++){
		if(!fangyeMax.empty() && fangyeMax.front() == i - k) fangyeMax.pop_front();
		while(!fangyeMax.empty() && data[fangyeMax.back()] <= data[i]){
			fangyeMax.pop_back();
		}
		fangyeMax.push_back(i);
		printf("%d ", data[fangyeMax.front()]);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator