码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 3706 单调队列水题

时间:2015-01-14 15:33:37      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:单调队列


#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;

int num[1000001],id[1000001];
int main()
{
    int n,A,B;
    int i,j;
    while(~scanf("%d%d%d",&n,&A,&B))
    {
        int front=0;
        int top=0;
        __int64 x=1,sum=1;
        for(i=1;i<=n;i++)
        {
            x=(x*A)%B;
            while(front<top&&num[top]>x)
            top--;
            num[++top]=x;
            id[top]=i;
            while(id[front+1]<i-A) front++;
            sum=(sum*num[front+1])%B;
        }
        printf("%I64d\n",sum);
    }    
    return 0;
}

hdu 3706 单调队列水题

标签:单调队列

原文地址:http://blog.csdn.net/zxf654073270/article/details/42710097

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!