题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=5475

Problem Description
One day, a useless calculator was being built by Kuros. Let's assume that number X is showed on the screen of calculator. At first, X = 1. This calculator only supports two types of operation.
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.
 
Input
The first line is an integer T(1≤T≤10), indicating the number of test cases.
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.

 
Output
For each test case, the first line, please output "Case #x:" and x is the id of the test cases starting from 1.
Then Q lines follow, each line please output an answer showed by the calculator.
 
Sample Input
1
10 1000000000
1 2
2 1
1 2
1 10
2 3
2 4
1 6
1 7
1 12
2 7
 
Sample Output
Case #1:
2
1
2
20
10
1
6
42
504
84
 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5932 5931 5930 5929 5928 
 
题意:输入Q和M,然后输入Q次操作,每次操作为一行数据op和s,定义一个数x=1。如果op=1表示x=x*s%mod 输出x,如果op=2 表示x除以第s次操作的s(第s次操作的op一定为1),输出x;
 
思路:线段树点修改,每次操作时,修改那个点,复杂度为log(n),如果op=1,那么修改为s,如果op=2,那么第s次操作对应的点修改为1;
 
代码如下:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
LL mod;
LL tr[*];
int p;
LL add;
void build(int l,int r,int i)
{
if(l==r) {
tr[i]=;
return ;
}
int mid=(l+r)>>;
build(l,mid,i<<);
build(mid+,r,i<<|);
tr[i]=;
} void update(int l,int r,int i)
{
if(l==r) { tr[i]=add; return ; }
int mid=(l+r)>>;
if(p<=mid) update(l,mid,i<<);
else update(mid+,r,i<<|);
tr[i]=(tr[i<<]*tr[i<<|])%mod;
} int main()
{
int T,Q,Case=;
cin>>T;
while(T--)
{
scanf("%d%lld",&Q,&mod);
printf("Case #%d:\n",Case++);
build(,Q,);
for(int i=;i<=Q;i++)
{
int x;
LL y;
scanf("%d%lld",&x,&y);
if(x==) { p=i; add=y; }
else { p=y; add=; }
update(,Q,);
printf("%lld\n",tr[]);
}
}
return ;
}

HDU 5475(2015 ICPC上海站网络赛)--- An easy problem(线段树点修改)的更多相关文章

  1. HDU 4747 Mex (2013杭州网络赛1010题,线段树)

    Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  2. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  3. 2015上海网络赛 HDU 5475 An easy problem 线段树

    题意就不说了 思路:线段树,维护区间乘积.2操作就将要除的点更新为1. #include<iostream> #include<cstdio> #include<cstr ...

  4. HDU 4267 A Simple Problem with Integers(2012年长春网络赛A 多颗线段树+单点查询)

    以前似乎做过类似的不过当时完全不会.现在看到就有点思路了,开始还有洋洋得意得觉得自己有不小的进步了,结果思路错了...改了很久后测试数据过了还果断爆空间... 给你一串数字A,然后是两种操作: &qu ...

  5. HDU 6444 Neko's loop ( 2018 CCPC 网络赛 && 裴蜀定理 && 线段树 )

    题目链接 题意 : 给出一个 n 个元素的环.可以任意选择起点.选完起点后.可以行走 m 步.每次前进 k 个单位.所走到的点将产生正或负贡献.问你一开始得准备多少才能使得初始资金加上在环上获取最大利 ...

  6. 2017ICPC北京赛区网络赛 Minimum(数学+线段树)

    描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...

  7. 2017 ICPC西安区域赛 A - XOR (线段树并线性基)

    链接:https://nanti.jisuanke.com/t/A1607 题面:   Consider an array AA with n elements . Each of its eleme ...

  8. 2019ICPC上海网络赛A 边分治+线段树

    题目: 给定一棵树, 带边权. 现在有2种操作: 1.修改第i条边的权值. 2.询问u到其他一个任意点的最大距离是多少. 解法:边分治+线段树 首先我们将所有的点修改和边修改都存在对应的边里面. 然后 ...

  9. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

随机推荐

  1. appledoc 使用brew命令安装使用

    appledoc --project-name yushuyi12345677 --project-company "xiaoyu123" --company-id aaaa -- ...

  2. 原生JS下拉加载插件分享。

    无聊写了一个JS下拉加载插件,有需要的可以下载. // 使用 // new ManDownLoad("#ul","json/load.json",functio ...

  3. 【SQL】SQL Server登录常见问题

    很多人SQL装的很不规范,导致各种问题或者说时间长了,密码给忘记了,怎么办呢?重装? 逆天就拿几个比较常见的来说事吧,首先是各种设置的问题:(我家里用的是简易版,你们开发最好用企业版)         ...

  4. Entity Framework Code First执行SQL语句、视图及存储过程

    1.Entity Framework Code First查询视图 Entity Framework Code First目前还没有特别针对View操作的方法,但对于可更新的视图,可以采用与Table ...

  5. 推荐12个漂亮的 CSS3 按钮实现方案

    在过去,我们都是使用图片或者JavaScript来实现漂亮的按钮效果,随着越来越多的浏览器对CSS3的支持和完善,使用CSS3来实现美观的按钮已没有太多的障碍.今天,本文收集了12个很不错的CSS3按 ...

  6. 虚拟 ​router 原理分析- 每天5分钟玩转 OpenStack(101)

    上一节我们创建了虚拟路由器"router_100_101",并通过 ping 验证了 vlan100 和 vlan101 已经连通. 本节将重点分析其中的原理. 首先我们查看控制节 ...

  7. 掌握 Cinder 的设计思想 - 每天5分钟玩转 OpenStack(46)

    上一节介绍了 Cinder 的架构,这节讨论 Cinder 个组件如何协同工作及其设计思想. 从 volume 创建流程看 cinder-* 子服务如何协同工作 对于 Cinder 学习来说,Volu ...

  8. Android随笔之——闹钟制作铺垫之AlarmManager详解

    说实话,之前写的两篇博客Android广播机制Broadcast详解.Android时间.日期相关类和方法以及现在要写的,都算是为之后要写的闹钟应用做铺垫,有兴趣的话,大家可以去看看前两篇博客. 一. ...

  9. Last-Modified、If-Modified-Since 实现缓存和 OutputCache 的区别

    先梳理三个概念: OutputCache:页面输出缓存,一般 ASP.NET 应用程序会用到. Last-Modified:Http 响应头(Http Reponse Header),由服务器发给客户 ...

  10. 关于有默认值的字段在用EF做插入操作时的思考(续)

    问题描述 今天下午(看现在这时间,应该是昨天下午了哈),园友 choon 写了这样一篇博文<关于有默认值的字段在用EF做插入操作时的思考>. 博文内容主要记录的是 choon 使用 EF ...