题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3706

Second My Problem First

Time Limit: 12000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description
Give you three integers n, A and B. 
Then we define Si = Ai mod B and Ti = Min{ Sk | i-A <= k <= i, k >= 1}
Your task is to calculate the product of Ti (1 <= i <= n) mod B.
 
Input
Each line will contain three integers n(1 <= n <= 107),A and B(1 <= A, B <= 231-1). 
Process to end of file.
 
Output
For each case, output the answer in a single line.
 
Sample Input
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
 
Sample Output
2
3
4
5
6
 
Author
WhereIsHeroFrom@HDU
 
Source
 
单调队列简单题;
卡内存,list过不了,deque,G++过的;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e7+,M=4e6+,inf=;
const ll INF=1e18+,mod=1e9+;
/// 数组大小
int d[N];
ll num[N];
int main()
{
ll n,a,b;
while(~scanf("%lld%lld%lld",&n,&a,&b))
{
ll ans=,base=a%b;
int s=,e=;
for(int i=;i<=n;i++,base=(base*a)%b)
{
num[i]=base;
while(s<e&&d[s]<i-a)s++;
while(e>s&&num[d[e]]>=num[i])e--;
d[++e]=i;
//cout<<num[d[s+1]]<<" "<<endl;
ans=ans*(num[d[s+]])%b;
}
printf("%lld\n",ans);
}
return ;
}

hdu 3706 Second My Problem First 单调队列的更多相关文章

  1. HDU 4123(树的直径+单调队列)

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. HDU 4122 Alice's mooncake shop 单调队列优化dp

    Alice's mooncake shop Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

  3. hdu 4122 Alice's mooncake shop(单调队列)

    题目链接:hdu 4122 Alice's mooncake shop 题意: 有n个订单和可以在m小时内制作月饼 接下来是n个订单的信息:需要在mon月,d日,year年,h小时交付订单r个月饼 接 ...

  4. hdu 3415 Max Sum of Max-K-sub-sequence(单调队列)

    题目链接:hdu 3415 Max Sum of Max-K-sub-sequence 题意: 给你一串形成环的数,让你找一段长度不大于k的子段使得和最大. 题解: 我们先把头和尾拼起来,令前i个数的 ...

  5. 【HDU】3401:Trade【单调队列优化DP】

    Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. ACM学习历程—HDU 5289 Assignment(线段树 || RMQ || 单调队列)

    Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered fro ...

  7. HDU 4193 Non-negative Partial Sums【单调队列】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4193 题意: 给定序列,可以把后面的连续的部分移到最前面来,问多少种移法使得最终得到的序列的前i项和 ...

  8. HDU 4374 One hundred layer(单调队列DP)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=116242#problem/E 题意:差不多就是男人勇下百层的游戏.从第一层到最 ...

  9. HDU 4193 Non-negative Partial Sums(单调队列)

     题目大意: 给定一个长度为n的循环序列.从n个不同位置開始,问有几个位置使得一下情况成立:全部前缀的和都大等于0(n <=1000000). 下午的训练赛.之前没学过单调队列所以用的线段树 ...

随机推荐

  1. for与while的特点及其if在什么情况下使用情况

    for和while的特点: 什么时候使用循环结构呢? 1:当对某些代码执行很多次时,使用循环结构完成. 2:当对一个条件进行一次判断时,可以使用if语句. 3:当对一个条件进行多次判断时,可以使用wh ...

  2. 实习培训——Servlet(5)

    实习培训——Servlet(5) 1  Servlet 简介 Servlet 是什么? Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HT ...

  3. Python 使用ctypes调用 C 函数

    在python中通过ctypes可以直接调用c的函数,非常简单易用 下面就一步一步解释用法吧,以Linux为例讲解. 1, 首先确定你的python支持不支持ctypes python2.7以后cty ...

  4. (转)Elasticsearch分析聚合

    Elasticsearch不仅仅适合做全文检索,分析聚合功能也很好用.下面通过实例来学习. 一.准备数据 {"index":{ "_index": " ...

  5. Javaweb开发请求

    1.Ajax jQuery对Ajax支持:$.ajax({  }); ==>常用参数:url:请求地址,type:post|get,data:请求参数,dataType:服务器返回数据类型,su ...

  6. 【Cocos2dx 3.3】图片裁剪

        从一个图片集中裁剪出需要的图片时,采用的坐标是屏幕坐标系:        示例如下:    图片:res/Images/grossini_dance_atlas.png ,每个人物大小为85* ...

  7. [ps] 灰度和通道基础知识

    灰度.灰度值.灰度图像 灰度:灰度使用黑色调来表示物体,即用黑色为基准色,不同饱和度的黑色来显示图像.每个灰度对象都具有从0%(白色)到100%(黑色)的亮度值.使用黑白或灰度扫描仪生成的图像通常以灰 ...

  8. 接口测试xml格式转换成json

    未经允许,禁止转载!!!! 接口测试一般返回的是xml和json,现在大多数时候是返回成json的格式,但是有时候也会出现xml格式, 由于xml格式的文件阅读起来不是很容易懂,所以尽量将xml转换成 ...

  9. vscode 搭建react-native

    vscode 搭建react-native 选择:vscode + typings + eslint * vscode: 宇宙最强IDE家族的最新产品 * typings: 基于typescirpt的 ...

  10. Air Jordan 1 Los Primeros Will be unveiled

    This new pair of Air Jordan 1 Los Primeros is part of the popular Air-Jordan- Line signature and is ...