题意就不说了

思路:线段树,维护区间乘积。2操作就将要除的点更新为1.

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define inf 0x3f3f3f3f
#define LL long long
#define mid(a,b) ((a+b)>>1)
#define ll long long
#define maxn 110000
#define IN freopen("in.txt","r",stdin);
using namespace std; LL mod;
LL num[maxn];
struct Tree
{
int left,right;
LL pro; /*pro为区间和,可改为最大值最小值等*/
}tree[maxn<<]; /*四倍大小*/ /*递归建树*/
void build(int i,int left,int right)
{
tree[i].left=left;
tree[i].right=right; if(left==right){
tree[i].pro=num[left]%mod;
return ;
} int mid=mid(left,right); build(i<<,left,mid);
build(i<<|,mid+,right); tree[i].pro=(tree[i<<].pro*tree[i<<|].pro)%mod;
} /*单点修改,d为改变量,两函数可共存*/
void update(int i,int x,LL d)
{
if(tree[i].left==tree[i].right){
tree[i].pro=d;
return;
} int mid=mid(tree[i].left,tree[i].right); if(x<=mid) update(i<<,x,d);
else update(i<<|,x,d); tree[i].pro=(tree[i<<].pro*tree[i<<|].pro)%mod;
} /*区间结果查询*/
LL query(int i,int left,int right)
{
if(tree[i].left==left&&tree[i].right==right)
return tree[i].pro%mod; int mid=mid(tree[i].left,tree[i].right); if(right<=mid) return query(i<<,left,right);
else if(left>mid) return query(i<<|,left,right);
else return (query(i<<,left,mid)*query(i<<|,mid+,right))%mod;
} int main(int argc, char const *argv[])
{
//IN; int t,ca=;scanf("%d",&t);
while(t--)
{
printf("Case #%d:\n",ca++);
int n;scanf("%d %lld",&n,&mod);
//fill(num,num+maxn,1);
int type[maxn];LL val[maxn];
for(int i=;i<=n;i++){
scanf("%d %lld",&type[i],&val[i]);
if(type[i]==) num[i]=val[i];
if(type[i]==) num[i]=;
}
build(,,n);
for(int i=;i<=n;i++){
if(type[i]==){
LL ans=query(,,i);
printf("%lld\n",ans%mod);
}
else if(type[i]==){
update(,val[i],1LL);
LL ans=query(,,i);
printf("%lld\n",ans%mod);
}
} } return ;
}

2015上海网络赛 HDU 5475 An easy problem 线段树的更多相关文章

  1. 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)

    HDU 5489 Removed Interval 题意: 求序列中切掉连续的L长度后的最长上升序列 思路: 从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值, ...

  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 5478 Can you find it 数学

    HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 #include <iostre ...

  4. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  5. hud-5475 An easy problem(线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  6. CCPC 2019 网络赛 1002 array (权值线段树)

    HDU 6703 array   题意:   给定一个数组 \(a_1,a_2, a_3,...a_n\) ,满足 \(1 \le a[i]\le n\) 且 \(a[i]\) 互不相同.   有两种 ...

  7. hdu 5476 Explore Track of Point(2015上海网络赛)

    题目链接:hdu 5476 今天和队友们搞出3道水题后就一直卡在这儿了,唉,真惨啊……看着被一名一名地挤出晋级名次,确实很不好受,这道恶心的几何题被我们3个搞了3.4个小时,我想到一半时发现样例输出是 ...

  8. 2015合肥网络赛 HDU 5492 Find a path 动归

    HDU 5492 Find a path 题意:给你一个矩阵求一个路径使得 最小. 思路: 方法一:数据特别小,直接枚举权值和(n + m - 1) * aver,更新答案. 方法二:用f[i][j] ...

  9. 2015上海网络赛 A Puzzled Elena

    题意:给定一棵树,求这个节点的所有子树中包括他本身与它互质的节点的个数. 解题思路:题利用dfs序+容斥原理+前缀和性质解决.题目中要求每个结点,和多少个它的子结点互素.如果每次为了求一个点去跑一遍d ...

随机推荐

  1. wordcontent结对编程

    合作者:201631062625 201631062127 代码地址:https://gitee.com/yzpdegit/ts 本次作业链接:https://www.cnblogs.com/yang ...

  2. python 面向对象 类方法,静态方法,property

    property 内置装饰器函数 只在面向对象使用 把方法当初属性使用(方法不加参数) 例子: class Rectangle: def __init__(self,long,wide,color): ...

  3. HDU 4725 The Shortest Path in Nya Graph

    he Shortest Path in Nya Graph Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged o ...

  4. [React] Use React Fragments to make your DOM tree cleaner

    In this lesson, we will look at Fragments and how they are useful in achieving a cleaner DOM structu ...

  5. mysql-通过例子解释四种隔离级别

    SQL标准定义了4种隔离级别,包括了一些具体规则,用来限定事务内外的哪些改变是可见的,哪些是不可见的. 低级别的隔离级一般支持更高的并发处理,并拥有更低的系统开销. 首先,我们使用 test 数据库, ...

  6. &lt;&lt;Python基础教程&gt;&gt;学习笔记 | 第12章 | 图形用户界面

    Python支持的工具包非常多.但没有一个被觉得标准的工具包.用户选择的自由度大些.本章主要介绍最成熟的跨平台工具包wxPython.官方文档: http://wxpython.org/ ------ ...

  7. Thinkphp 无法使用-&gt;order() 排序的两种解决的方法!

    使用ThinkPHP,却发现无法使用->order($order)来排序. $order = " info.date2 desc "; 非常遗憾的是这样写结果order却变成 ...

  8. 图像几何变换(geometric transformation)

    1. imwarp B = imwarp(A,tform) demo I = imread('cameraman.tif'); tform = affine2d([1 0 0; .5 1 0; 0 0 ...

  9. Spring 4 CustomEditorConfigurer Example--转

    原文地址:http://howtodoinjava.com/spring/spring-core/registering-built-in-property-editors-in-spring-4-c ...

  10. 集合区别(list和linkedlist的区别)?

    1.list和linkedlist都是有序可重复,为什么还要用linkedlist呢? 数组和数组列表都有一个重大的缺陷,这就是从数组的中间位置删除一个元素需要付出很大的代价,其原因是数组中处于被删除 ...