2015上海网络赛 HDU 5475 An easy problem 线段树
题意就不说了
思路:线段树,维护区间乘积。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 线段树的更多相关文章
- 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
HDU 5489 Removed Interval 题意: 求序列中切掉连续的L长度后的最长上升序列 思路: 从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值, ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- 2015上海网络赛 HDU 5478 Can you find it 数学
HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 #include <iostre ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- hud-5475 An easy problem(线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- CCPC 2019 网络赛 1002 array (权值线段树)
HDU 6703 array 题意: 给定一个数组 \(a_1,a_2, a_3,...a_n\) ,满足 \(1 \le a[i]\le n\) 且 \(a[i]\) 互不相同. 有两种 ...
- hdu 5476 Explore Track of Point(2015上海网络赛)
题目链接:hdu 5476 今天和队友们搞出3道水题后就一直卡在这儿了,唉,真惨啊……看着被一名一名地挤出晋级名次,确实很不好受,这道恶心的几何题被我们3个搞了3.4个小时,我想到一半时发现样例输出是 ...
- 2015合肥网络赛 HDU 5492 Find a path 动归
HDU 5492 Find a path 题意:给你一个矩阵求一个路径使得 最小. 思路: 方法一:数据特别小,直接枚举权值和(n + m - 1) * aver,更新答案. 方法二:用f[i][j] ...
- 2015上海网络赛 A Puzzled Elena
题意:给定一棵树,求这个节点的所有子树中包括他本身与它互质的节点的个数. 解题思路:题利用dfs序+容斥原理+前缀和性质解决.题目中要求每个结点,和多少个它的子结点互素.如果每次为了求一个点去跑一遍d ...
随机推荐
- Python学习笔记(二):字符串类型
在上一篇随笔(https://www.cnblogs.com/g-qiang/p/10448813.html)中,说到 Python 有六种标准数据类型,而数字类型和字符串类型又是其中基本的数据类型. ...
- 关于Android制作.9.png图片
第一个问题,.9格式的图片与我们之前的一般图片有什么问题呢? 这是安卓开发里面的一种特殊的图片. 这样的格式的图片在android 环境下具有自适应调节大小的能力. (1)同意开发者定义可扩展区域,当 ...
- sublime搜索和替换--多文件搜索替换
Search and Replace - Multiple Files Searching To open the search panel for files, press Ctrl + Shift ...
- win7 一个电脑接入多个显示器
Display 在第一个选项display,选中某一个屏幕的时候 如果被选中的屏幕已经是main display,那么下方会显示this is your currently main display ...
- sklearn.preprocessing OneHotEncoder——仅仅是数值型字段才可以,如果是字符类型字段则不能直接搞定
>>> from sklearn.preprocessing import OneHotEncoder >>> enc = OneHotEncoder() > ...
- visual studio code(vscode)的使用(快捷键)
Visual Studio Code初探 vscode 是一种可运行于 OS X,Windows 和 Linux 之上的免费跨平台编辑器: 1. 快捷键 ctrl + `:调出(对于 windows ...
- [BZOJ3884] 上帝与集合的正确用法 (欧拉函数)
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3884 题目大意: 给出 M, 求 $2^{2^{2^{2^{...}}}}$ % M ...
- BZOJ 1174: [Balkan2007]Toponyms
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 735 Solved: 102[Submit][Status][Discuss] Descriptio ...
- iOS崩溃日志
今天看crash report ,有这样两个crash: 调用 stopUpdatingLocation 函数的是一个CLLocationManager 类型的对象,为什么报错的时候会把这个对象转成N ...
- 解决VMware Pro 14安装Linux镜像时黑屏问题
软件及版本: VMware-workstation-full-14.0.0-6661328 CentOS-6.8-x86_64-bin-DVD1 系统: win10 问题: 启动虚拟机,配置完cent ...