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

G++TLE C++AC这是为什么 有人帮忙解答下吗

Posted by S031502541 at 2016-09-04 12:25:15 on Problem 2823
#include<stdio.h>
#include<string.h>
const int maxn = 1000005;
int a[maxn],q[maxn];
int n,k;

void Monotonequeue(int op)
{
    memset(q,0,sizeof(q));
    bool first = true;
    int head = 1,tail = 0;
    for (int i = 1; i <= n; i++)
    {
        while (head <= tail && ((!op && a[i] <= a[q[tail]]) || (op && a[i] >= a[q[tail]])))	tail--;
        q[++tail] = i;
        while (head <= tail && q[tail] - q[head] >= k)	head++;
        if (i >= k)	first?printf("%d",a[q[head]]):printf(" %d",a[q[head]]),first = false;
    }
    printf("\n");
}

int main()
{
    scanf("%d%d",&n,&k);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
    }
    Monotonequeue(0);
    Monotonequeue(1);
    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