题目链接

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. CVTE实习求职经历

    今天,听到有好多同学最近要去面试CVTE这家企业,于是呢,准备将自己的经历写上来,给大家一个参考,希望能够大家一次帮助. 一.整体感觉 首先呢,先讲一下我个人对这家企业的整体感觉吧. 1. 第一次 对 ...

  2. Java this的一两点使用

    Java this的一两点使用 之前的文章都是关于Android的使用,这次想写一些关于Java的知识,总结一下Java的使用.这次写的是关于Java this的使用,介绍以下内容: this的概念 ...

  3. Jass 技能模型定义(—):半人马酋长的反击光环

      Jass是什么?       先阐释一下什么是jass吧,百度:JASS(正确地说是JASS 2)是魔兽3的程序语言,用于控制游戏和地图的进行,也是魔兽游戏和地图的基础. 地图编辑器中摆放的单位( ...

  4. react-native 简述

    1. RN 是什么 2. RN 与传统Hybrid框架相比的优势 3. RN的优势 4. RN的劣势 5. RN开发重点关注的问题 1 RN是什么 2 RN 与传统Hybrid框架相比的优势 传统的如 ...

  5. TSQL “匹配全部”语义的实现

    在TSQL中,有exists子句表示存在,表示匹配任意一行数据,但是,如何表示匹配全部的数据行.例如,表示一个学生选修了所有课程,这就是“匹配全部”语义的一个经典实例. 示例,获取“选修全部”课程的学 ...

  6. Clash Detection

    Clash Detection eryar@163.com Abstract. Clash detection is used for the model collision check. The p ...

  7. A Simple OpenGL Shader Example

    A Simple OpenGL Shader Example eryar@163.com Abstract. OpenGL Shading Language, the high-level progr ...

  8. 前端学PHP之面向对象系列第三篇——三大特性

    × 目录 [1]封装 [2]继承[3]多态 前面的话 php面向对象编程的三大特性是封装性.继承性和多态性.本文将介绍php的这三大特性 封装 封装就是把对象中的成员属性和成员方法加上访问修饰符( p ...

  9. 辨析relative与absolute

    谈起它们,想必大家都不陌生.relative,相对定位嘛:absolute,绝对定位嘛.但是它们到底是个啥东东呢? 看看w3c的定义,见下表 定位 含义 relative 元素框偏移某个距离.元素仍保 ...

  10. 应用程序框架实战三十三:表现层及ASP.NET MVC介绍(二)

    最近的更新速度越来越慢,主要是项目上比较忙,封装EasyUi也要花很多时间.不过大家请放心,本系列不会半途夭折,并且代码干货也会持续更新.本文继续介绍表现层和Asp.net Mvc,我将在本篇讨论一些 ...