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 ...
随机推荐
- MySQL多版本并发控制——MVCC机制分析
MVCC,即多版本并发控制(Multi-Version Concurrency Control)指的是,通过版本链维护一个数据的多个版本,使得读写操作没有冲突,可保证不同事务读写.写读操作并发执行,提 ...
- 如何实现CentOS服务器的扩容??
Linux的硬盘识别: 一般使用"fdisk -l"命令可以列出系统中当前连接的硬盘 设备和分区信息.新硬盘没有分区信息,则只显示硬盘大小信息. 1.关闭服务器加上新硬盘 2.启动 ...
- MySQL使用SQL操作数据表的增加、修改和删除
表的修改和删除 修改 -- 修改表名称 -- ALTER TABLE 旧表名 RENAME AS 新表名 ALTER TABLE test RENAME AS test1 -- 增加表字段 -- AL ...
- 【SpringBoot】Spring Boot,开发社区讨论交流网站首页。
初识Spring Boot,开发社区讨论交流网站首页. 文章目录 初识Spring Boot,开发社区讨论交流网站首页. 1.项目简介 2. 搭建开发环境 JDK Apache Maven Intel ...
- dig的安装和使用
-bash: dig: command not found 解决办法: yum -y install bind-utils dig www.baid bu.com 查看a记录 dig www.ba ...
- 【ORA】ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode 这个问题是rman备份的时候,发现有问题 原因: 数据库没有开启归档 ...
- java中如何踢人下线?封禁某个账号后使其会话立即掉线!
需求场景 封禁账号是一个比较常见的业务需求,尤其是在论坛.社区类型的项目中,当出现了违规用户时我们需要将其账号立即封禁. 常规的设计思路是:在设计用户表时增加一个状态字段,例如:status,其值为1 ...
- kubernets集群的安全防护(下)
一 集群角色以及集群角色绑定 1.1 前面我们提到过角色以及角色绑定,那么现在为什么会出现集群级别的角色以及角色绑定,作用有如下所示 我们如果需要在所有的命名的空间创建某个角色或者角色绑定的时候 ...
- 【Azure Developer】解决Azure Key Vault管理Storage的示例代码在中国区Azure遇见的各种认证/授权问题 - C# Example Code
问题描述 使用Azure密钥保管库(Key Vault)来托管存储账号(Storage Account)密钥的示例中,从Github中下载的示例代码在中国区Azure运行时候会遇见各种认证和授权问题, ...
- Git 创建新分支检查分支
创建分支和切换分支,也可以称为检出分支 创建新分支 git branch branchName 切换到新分支 git checkout branchName 上面两个命令也可以合成为一个命令: git ...