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

编译成功运行崩,菜鸟求大神指点

Posted by Asmodians at 2016-09-17 14:29:25 on Problem 2823
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <deque>
#define N 1000005

using namespace std;

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int x, minx[N], maxx[N];
    int j = 0;

    deque <int>  Q, q, M, m;

    scanf("%d", &x);
    Q.push_front(x);
    q.push_front(x);
    M.push_front(1);
    m.push_front(1);


    for(int i = 2; i < k; i++)
    {
        scanf("%d", &x);

        while(x<q.back()&&!q.empty())
        {
            q.pop_back();
            m.pop_back();
        }

        q.push_back(x);
        m.push_back(i);

        while(x>Q.back()&&!Q.empty())
        {
            Q.pop_back();
            M.pop_back();
        }

        Q.push_back(x);
        M.push_back(i);
    }

    for(int i = k; i <= n; i++)
    {
        scanf("%d", &x);

        if(m.front()<=i-k)
        {
            q.pop_front();
            m.pop_front();
        }
        if(M.front()<=i-k)
        {
            Q.pop_front();
            M.pop_front();
        }

        while(x<q.back()&&!q.empty())
        {
            q.pop_back();
            m.pop_back();
        }

        q.push_back(x);
        m.push_back(i);

        while(x>Q.back()&&!Q.empty())
        {
            Q.pop_back();
            M.pop_back();
        }

        Q.push_back(x);
        M.push_back(i);

        minx[j] = q.front();
        maxx[j] = Q.front();
        j++;

    }

    for(int i = 0; i < j; i++)
    {
        printf("%d", minx[i]);
    }
    printf("\n");
    for(int i = 0; i < j; i++)
    {
        printf("%d", maxx[i]);
    }

    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