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)
Total Submission(s): 1330    Accepted Submission(s):
503

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
#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[];
//int p[1000010];
int main()
{
__int64 a,b;
int n,i,t;
while(~scanf("%d%I64d%I64d",&n,&a,&b))
{
__int64 ti=;
__int64 s=; int head=,r=;
for(i=;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+].p<i-a)
head++;
ti=(ti*q1[head+].num)%b; }
printf("%I64d\n",ti);
}
return ;
}

HDU-3706 Second My Problem First的更多相关文章

  1. hdu 3706 Second My Problem First 单调队列

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3706 Second My Problem First Time Limit: 12000/4000 M ...

  2. HDU 5832 A water problem(某水题)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. hdu 1402 A * B Problem Plus FFT

    /* hdu 1402 A * B Problem Plus FFT 这是我的第二道FFT的题 第一题是完全照着别人的代码敲出来的,也不明白是什么意思 这个代码是在前一题的基础上改的 做完这个题,我才 ...

  4. HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online)

    HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online) 题目链接http://acm.hdu.edu.cn/showp ...

  5. hdu 2993 MAX Average Problem(斜率DP入门题)

    题目链接:hdu 2993 MAX Average Problem 题意: 给一个长度为 n 的序列,找出长度 >= k 的平均值最大的连续子序列. 题解: 这题是论文的原题,请参照2004集训 ...

  6. [HDU - 5170GTY's math problem 数的精度类

    题目链接:HDU - 5170GTY's math problem 题目描述 Description GTY is a GodBull who will get an Au in NOI . To h ...

  7. cdq分治(hdu 5618 Jam's problem again[陌上花开]、CQOI 2011 动态逆序对、hdu 4742 Pinball Game、hdu 4456 Crowd、[HEOI2016/TJOI2016]序列、[NOI2007]货币兑换 )

    hdu 5618 Jam's problem again #include <bits/stdc++.h> #define MAXN 100010 using namespace std; ...

  8. HDOJ(HDU).1016 Prime Ring Problem (DFS)

    HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  9. 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)

    数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...

  10. Hdu 5371 Hotaru's problem (manacher+枚举)

    题目链接: Hdu 5371 Hotaru's problem 题目描述: 给出一个字符串N,要求找出一条N的最长连续子串.这个子串要满足:1:可以平均分成三段,2:第一段和第三段相等,3:第一段和第 ...

随机推荐

  1. 替换a链接的href和title

    新项目准备验收,客户检测网页有安全隐患,说是当前网页使用“http://”有风险,指定外部链接不用“http://”怎么整…… 后来想到用JS替换字符串去操作,找了半天总算找到合用的,最终是用JQ去更 ...

  2. mysql基本知识

    最大连接数show variables max_connections; select VARIABLE_VALUE from information_schema.GLOBAL_VARIABLES ...

  3. winform水晶报表编译错误,未能加载文件或程序集"file:///C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framewor "

    未能加载文件或程序集“file:///C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Commo ...

  4. HttpWebRequest中的SendChunked

    MSDN上说:When SendChunked is true, the request sends data to the Internet resource in segments. The In ...

  5. javascript学习笔记2

    二.下列哪些变量是不正确的  说明原因 var a1; var b1 = 3; c1 ='good'; var d1 = c1 = e1;   ×  连等必须赋值 var g1 = 'hei' goo ...

  6. Windows 下Python操作MySQL

    1.环境要求(Win7 X64): python 2.7, MySQL-python-1.2.3.win-amd64-py2.7 :http://www.codegood.com/download/1 ...

  7. Andorid游戏2048开发(一)

    最近有一款Android平台下的游戏很是火爆----2048.下面记录一下开发过程.由于笔者是Android开发的初学者,所以希望借以此文熟悉整个Android开发的流程. 首先创建Game2048的 ...

  8. 【3】Bootstrap的下载和目录结构

    [1]下载 去中方官网下载http://www.bootcss.com/ 如果你是做网页练习,你可以使用CDN加速服务,免去下载等痛苦,当然你使用的时候必须有连接上网络.中方的官网也提供了很多种类的C ...

  9. ZeroMQ/jzmq安装使用

    环境: No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 12.04.2 LTS Release: 12 ...

  10. SQL常用命令浅析

    表操作备注:操作之前使用“use <数据库名>”应连接某个数据库.建表命令:create table <表名> (<字段名 1> <类型 1> [,.. ...