hdu3706 Second My Problem First
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.
Process to end of file.
2 3 4
3 4 5
4 5 6
5 6 7
3
4
5
6
这题可以用单调队列做,存储每次的时间和大小。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
#define maxn 10000005
#define ll __int64
ll q[maxn][2];
int main()
{
ll n,m,A,B,ans,front,rear,time,sum,timenow;
int i,j;
while(scanf("%I64d%I64d%I64d",&n,&A,&B)!=EOF)
{
front=1;rear=0;ans=1;sum=1;
for(i=1;i<=n;i++){
ans=(ans*A)%B;
if(i-A<1)time=1;
else time=i-A;
while(front<=rear && ans<=q[rear][0]){
rear--;
}
rear++;
q[rear][0]=ans;q[rear][1]=i;
while(front<=rear && q[front][1]<time)front++;
sum=(sum*q[front][0])%B;
}
printf("%I64d\n",sum%B);
}
return 0;
}
hdu3706 Second My Problem First的更多相关文章
- HDU-3706 Second My Problem First
http://acm.hdu.edu.cn/showproblem.php?pid=3706 Second My Problem First Time Limit: 12000/4000 MS (Ja ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
随机推荐
- 【C++】《C++ Primer 》第七章
第七章 类 一.定义抽象数据类型 类背后的基本思想:数据抽象(data abstraction)和封装(encapsulation). 数据抽象是一种依赖于接口(interface)和实现(imple ...
- Java内存模型与线程(二)线程的实现和线程的调度
先行先发生原则(happen-before原则) 先行先发生是指Java内存模型中定义的两项操作之间的偏序关系. 如果说A先行于B,其实就是说在发生B操作之前,操作A产生的影响能被操作B观察到,至于这 ...
- requests基础封装-get/post封装
字符串转化成字典: convert_to_dict.py: import jsonstr1 = '{"grant_type":"client_credential&qu ...
- Kubernetes CoreDNS 状态是 CrashLoopBackOff 报错
查看状态的时候,遇见coredns出现crashlookbackoff,首先我们来进行排错,不管是什么原因,查看coredns的详细信息,以及logs [root@k8s-master coredns ...
- 与数论的厮守05:gcd(a,b)=gcd(b,a mod b)的证明
\[设c=gcd(a,b),那么a可以表示为mc,b可以表示为nc的形式.然后令a=kb+r,那么我们就\\ 只需要证明gcd(b,r)=c即可.{\because}r=a-kb=mc-knc,{\t ...
- LTH7锂电池充放电IC完整方案
内容目录: A,LTH7贴片5脚充电芯片 PW4054 1, 单节的锂电池保护电路 单节为3.7V锂电池(也叫4.2V)和3.8V锂电池(也叫4.35V) 2, 单节的锂电池充电电路 ...
- java虚拟机入门(五)- 常见垃圾回收器及jvm实现
上节讲完了垃圾回收的基础,包括java的垃圾是什么,如何寻找以及常用的垃圾回收算法,那么那么多的理论知识讲完了,具体是什么样的东西在做着回收垃圾的事情呢?我们接下来就好好聊聊jvm中常用的垃圾回收器. ...
- mysql(连接查询和数据库设计)
--创建学生表 create table students ( id int unsigned not null auto_increment primary key, name varchar(20 ...
- axios用法
1 axios.get('https://api.apiopen.top/getJoke?type=all', { 2 params: {//用于传参 3 type: 'all' 4 } 5 }).t ...
- JAVAV EMAIL
package a; import java.util.Date;import java.util.Properties;import javax.mail.Authenticator;import ...