hdu 5475 线段树
An easy problem
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
1. multiply X with a number.
2. divide X with a number which was multiplied before.
After each operation, please output the number X modulo M.
For each test case, the first line are two integers Q and M. Q is the number of operations and M is described above. (1≤Q≤105,1≤M≤109)
The next Q lines, each line starts with an integer x indicating the type of operation.
if x is 1, an integer y is given, indicating the number to multiply. (0<y≤109)
if x is 2, an integer n is given. The calculator will divide the number which is multiplied in the nth operation. (the nth operation must be a type 1 operation.)
It's guaranteed that in type 2 operation, there won't be two same n.
Then Q lines follow, each line please output an answer showed by the calculator.
10 1000000000
1 2
2 1
1 2
1 10
2 3
2 4
1 6
1 7
1 12
2 7
2
1
2
20
10
1
6
42
504
84
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
ll sum[N<<],mod;
void pushup(int pos)
{
sum[pos]=(sum[pos<<|]*sum[pos<<])%mod;
}
void buildtree(int l,int r,int pos)
{
if(l==r)
{
sum[pos]=;
return;
}
int mid=(l+r)>>;
buildtree(l,mid,pos<<);
buildtree(mid+,r,pos<<|);
pushup(pos);
}
void update(int point,ll change,int l,int r,int pos)
{
if(l==r&&l==point)
{
sum[pos]=change;
return;
}
int mid=(l+r)>>;
if(point<=mid)
update(point,change,l,mid,pos<<);
else
update(point,change,mid+,r,pos<<|);
pushup(pos);
}
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%lld",&n,&mod);
buildtree(,n,);
printf("Case #%d:\n",cas++);
for(int i=;i<=n;i++)
{
int flag;
ll l;
scanf("%d%lld",&flag,&l);
if(flag==)
update(i,l,,n,);
else
update(l,,,n,);
printf("%lld\n",sum[]);
}
}
return ;
}
hdu 5475 线段树的更多相关文章
- hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)
Weak Pair Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- hdu 3974 线段树 将树弄到区间上
Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3436 线段树 一顿操作
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- hdu 3397 线段树双标记
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 4578 线段树(标记处理)
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others) ...
- hdu 4533 线段树(问题转化+)
威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- hdu 2871 线段树(各种操作)
Memory Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 4052 线段树扫描线、奇特处理
Adding New Machine Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 1542 线段树扫描(面积)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
随机推荐
- stage3D基础五-----Working with 3D cameras(转)
原文地址:http://www.adobe.com/cn/devnet/flashplayer/articles/3d-cameras.html 原文是英文的,这里就不贴了,内容主要介绍直接使用相机坐 ...
- ASP.NET MVC自定义视图引擎ViewEngine 创建Model的专属视图
MVC内置的视图引擎有WebForm view engine和Razor view engine,当然也可以自定义视图引擎ViewEngine. 本文想针对某个Model,自定义该Model的专属视图 ...
- C# virtual,override,new 整理
今天仔细学习了一下C#中virtual, override, new关键字,参考了网上的很多资料,现整理一下. Virtual: virtual 关键字用于修饰方法.属性.索引器或事件声明,并使它们可 ...
- NPOI 添加下拉列表
需求 给指定列添加下拉列表.如下图: 思路 NPOI的文档网站不能访问了,这里参考的POI文档. 加下拉列表有两种方式,一种直接写字符串,例如 new String[]{"10", ...
- man page及info page用法
Linux系统的在线求助man page与info page 先来了解一下Linux有多少命令呢?在文本模式下,你可以直接按下两个[Tab]按键,看看总共有多少命令可以让你用? [vbird@www ...
- Robot Motion - poj 1573
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11269 Accepted: 5486 Description A ...
- springmvc上传方法
/** * * @param file 上传的文件 * @param filePath 上传到那个目录 * @return 上传后的文件名字 * @throws IOException */ publ ...
- Ajax主要用来完成哪些工作?
AJAX 是与服务器交换数据并更新部分网页的艺术,在不重新加载整个页面的情况下. 它使用 JavaScript 在 web 浏览器与 web 服务器之间来发送和接收数据. ajax主要用于在页面内容加 ...
- 【转】使用 Python Mock 类进行单元测试
出处:https://www.oschina.net/translate/unit-testing-with-the-python-mock-class?lang=chs&page=2#
- 线程池 Future 带返回结果
package com.aibi.cmdc.bigscreen.action; import java.util.ArrayList; import java.util.HashMap; import ...