HDU-3706 Second My Problem First
2015-04-22 21:08
363 查看
http://acm.hdu.edu.cn/showproblem.php?pid=3706
Total Submission(s): 1330 Accepted Submission(s):
503
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
Each line will contain three integers n(1 <= n <=
107),A and B(1 <= A, B <= 231-1).
Process to end
of file.
[align=left]Output[/align]
For each case, output the answer in a single
line.
[align=left]Sample Input[/align]
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
[align=left]Sample Output[/align]
2
3
4
5
6
Second My Problem First
Time Limit: 12000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1330 Accepted Submission(s):
503
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
Each line will contain three integers n(1 <= n <=
107),A and B(1 <= A, B <= 231-1).
Process to end
of file.
[align=left]Output[/align]
For each case, output the answer in a single
line.
[align=left]Sample Input[/align]
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
[align=left]Sample Output[/align]
2
3
4
5
6
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<cmath> #define len 0x7fffffff using namespace std; struct node { __int64 num; int p; }; node q1[1000010]; //int p[1000010]; int main() { __int64 a,b; int n,i,t; while(~scanf("%d%I64d%I64d",&n,&a,&b)) { __int64 ti=1; __int64 s=1; int head=0,r=0; for(i=1;i<=n;i++) { s=(s*a)%b; while(head<r&&q1[r].num>=s) r--; q1[++r].num=s; q1[r].p=i; while(q1[head+1].p<i-a) head++; ti=(ti*q1[head+1].num)%b; } printf("%I64d\n",ti); } return 0; }
相关文章推荐
- 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 单调队列
- 单调队列1001 HDU 3706 Second My Problem First 单调队列入门题
- HDU 3706 Second My Problem First 【单调队列】
- hdu 3706 Second My Problem First
- 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
- hdu3706 Second My Problem First 滑动窗口最小值 单调队列
- HDU3706 Second My Problem First
- My first CXX problem:"aggregate has incomplete type and cannot be defined"
- My first blog!! About a problem in SQL 2005 configuration...
- hdu 3752 Is the one been second-killed first? 菜鸟杯
- Problem To My Girlfriend (HDU 5800)
- HDU 3752 Is the one been second-killed first?
- hdu 3752 Is the one been second-killed first?