hdu 3706 Second My Problem First
来源:互联网 发布:ai软件下载最新版 编辑:程序博客网 时间:2024/05/21 15:05
Second My Problem First
Time Limit: 12000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1223 Accepted Submission(s): 468
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.
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.
Process to end of file.
Output
For each case, output the answer in a single line.
Sample Input
1 2 32 3 43 4 54 5 65 6 7
Sample Output
23456
代码:
#include<cstdio>#include<iostream>#define Maxn 10000010#define ll long longusing namespace std;int p[Maxn],sq[Maxn<<1];int main(){ int n,a,b; while(~scanf("%d%d%d",&n,&a,&b)){ p[0]=1; for(int i=1;i<=n;i++) p[i]=p[i-1]*(ll)a%b; int s=0,e=-1; int res=1; for(int i=1;i<=n;i++){ while(s<=e&&p[sq[e]]>=p[i]) e--; sq[++e]=i; if(sq[s]+a-1<sq[e]) s++; res=(ll)res*p[sq[s]]%b; } printf("%d\n",res); }return 0;}
0 0
- hdu 3706 Second My Problem First
- HDU 3706 Second My Problem First
- HDU - 3706 Second My Problem First
- Second My Problem First HDU
- HDU 3706——Second My Problem First
- HDU 3706 Second My Problem First 单调队列简单题
- HDU 3706 Second My Problem First 【单调队列】
- hdu 3706 Second My Problem First(单调队列)
- hdu 3706 Second My Problem First(单调队列)
- hdu3706 Second My Problem First
- HDU3706-Second My Problem First
- 单调队列1001 HDU 3706 Second My Problem First 单调队列入门题
- Second My Problem First HDOJ 5th Anniversary Contest 1007
- hdu3706 Second My Problem First 滑动窗口最小值 单调队列
- 单调队列(基础题) HDU3706 Second My Problem First
- HDU3706Second My Problem First(单调队列)
- 【单调队列】HDU_3706_Second My Problem First
- hdu 3752 Is the one been second-killed first?
- C/C++ Linux 程序员必须了解的 10 个工具
- 使用Elasticsearch构建爬虫系统
- 【LeetCode】Combination Sum II
- 使用 WordPress 设计网站时要注意哪些问题
- 微信公众平台java开发详解(工程代码+解析)
- hdu 3706 Second My Problem First
- 第九章 9.1节练习 & 9.2节练习
- Thinkphp redirect
- C语言其实不简单:数组与指针
- ASP MVC最近遇到的两个问题(SQL和HTTPWebRequest)
- 解决SSh中公共Dao使用泛型且Dao层无其他Dao,Service直接继承公共Dao,部署到tomcat可能会出现的错误。
- window下lapack库和blas库的编译
- 2014/7/1学习计划与总结
- 想知道一个前辈或高手的sql水平