Number theory
思路:针对一个数组的操作,即对一个区间。可以用线段树去进行维护。初始化建树,叶子节点的值为1,维护每段区间上各个元素的乘积sum。M yi,将第i个元素的值改为yi。N di,将第di个元素的值改为1。输出即查询区间[1,Q]的sum值。也就是变成了单点更新、区间查询问题。
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
#include<set>
#include<iostream>
#define ll long long
#define lson p<<1
#define rson p<<1|1
using namespace std;
const int maxn=1e5+;
ll mod;
struct node
{
int l,r;
ll sum;
}t[maxn<<];
void pushup(int p)
{
t[p].sum=(t[lson].sum*t[rson].sum)%mod;
}
void build(int p,int l,int r)
{
t[p].l=l,t[p].r=r;
if(l==r)
{
t[p].sum=;
return ;
}
int mid=(l+r)>>;
build(lson,l,mid);
build(rson,mid+,r);
pushup(p);
}
void update(int p,int k,ll val)
{
if(t[p].l==t[p].r)
{
t[p].sum=val;
return ;
}
int mid=(t[p].l+t[p].r)>>;
if(k<=mid) update(lson,k,val);
else update(rson,k,val);
pushup(p);
}
int main()
{
int u;
ios::sync_with_stdio(false);
cin>>u;
while(u--)
{
int n,m;
cin>>n>>mod;
build(,,n);
for(int i=;i<=n;i++)
{
char s;
ll x;
cin>>s;
cin>>x;
if(s=='M')
update(,i,x);
else
update(,x,);
printf("%lld\n",t[].sum);
}
} }
Number theory的更多相关文章
- 2016级算法第二次上机-F.ModricWang's Number Theory II
		
891 ModricWang's Number Theory II 思路 使得序列的最大公约数不为1,就是大于等于2,就是找到一个大于等于2的数,它能够整除序列中的所有数. 考虑使得一个数d整除数组中 ...
 - 【BZOJ4026】dC Loves Number Theory 分解质因数+主席树
		
[BZOJ4026]dC Loves Number Theory Description dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源. 给 ...
 - BZOJ_4026_dC Loves Number Theory _主席树+欧拉函数
		
BZOJ_4026_dC Loves Number Theory _主席树+欧拉函数 Description dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯 竭 ...
 - Number Theory Problem(The 2016 ACM-ICPC Asia China-Final Contest 找规律)
		
题目: Mr. Panda is one of the top specialists on number theory all over the world. Now Mr. Panda is in ...
 - [E. Ehab's REAL Number Theory Problem](https://codeforces.com/contest/1325/problem/E) 数论+图论 求最小环
		
E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_i& ...
 - 题解-Ehab's REAL Number Theory Problem
		
Ehab's REAL Number Theory Problem 前置知识 质数 分解质因数 无向无权图最小环<讲> Ehab's REAL Number Theory Problem/ ...
 - BZOJ4026: dC Loves Number Theory
		
Description dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯 竭的水题资源. 给定一个长度为 n的正整数序列A,有q次询问,每次询问一段区间内所 ...
 - PARTITION(number theory) ALSO Explosive number in codewars
		
问题出于codewars,简言之:寻找和为一个整数的的不同整数组合.https://en.wikipedia.org/wiki/Partition_(number_theory) 例如:和为6的整数组 ...
 - HDU 2685 I won't tell you this is about number theory
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2685 题意:求gcd(a^m - 1, a^n - 1) mod k 思路:gcd(a^m - 1, ...
 - hdu 2685 I won't tell you this is about number theory   数论
		
题目链接 根据公式 \[ gcd(a^m-1, a^n-1) = a^{gcd(m, n)}-1 \] 就可以很容易的做出来了. #include <iostream> #include ...
 
随机推荐
- python中有哪些类型的布尔值是False?
			
1.None 2. False 3.所有的值为零的数 4."" 5.[] 6.() 7.{}
 - Azylee.Utils 工具组
			
https://github.com/yuzhengyang/Fork Fork 是平时做 C# 软件的时候,整合各种轮子的一个工具项目,包括并不仅限于:各种常用数据处理方法,文件读写 加密 搜索,系 ...
 - C 语言跟 C++ 的差异比较
			
C++ 完整的 CHM 版离线手册,可以 从这里下载. C++头文件不必是 .h 结尾 C语言中的标准库头文件,例如 math.h 和 stdio.h,在C++中被命名为 cmath 和 cstdio ...
 - altium笔记转载
			
原理图的设计 1.左键单击元器件按住space键可以将其旋转,按X键左右旋转:按Y键上下旋转. 2.智能粘贴:Edit àsmart paste . 3.屏障:compile mask(编译时被屏障的 ...
 - 多次最短路反思-Holy Grail
			
√ u=s[run],v=t[run]; ret=max(-d[v][u],-1000000000LL); dis[u][v]=ret;//d[u][v]= G[u].push_back(v); × ...
 - 解决:”ssh-keygen 不是内部或外部命令“ 的问题
			
相信大家在 码云生成/添加SSH公钥的过程中遇到一个比较常见的问题, 在cmd,命令行输入 ssh-keygen -t rsa -C "xxxxx@xxxxx.com" ; xxx ...
 - linux shell中的正则表达式
			
正则表达式的使用 正则表达式,又称规则表达式.(英语:Regular Expression [ˈreɡjulə] 规则的 [ iksˈpreʃən] 表达 ),在代码中常简写为regex.regexp ...
 - Java中的容器(集合)
			
1.Java常用容器:List,Set,Map List: 继承了Collection接口(public interface List<E> extends Collection<E ...
 - 【洛谷p3956】棋盘
			
日常blog(✧◡✧) 棋盘[题目链接] 算法: 然后这是2017普及组: first.关于颜色处理:让c[i][j]=color+1:这样无色=0,红色=1,黄色=2: 然后其实是记忆化,将记答案的 ...
 - C# 中File和FileStream的用法
			
原文:https://blog.csdn.net/qq_41209575/article/details/89178020 1.首先先介绍File类和FileStream文件流 1.1 File类, ...