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 ...
随机推荐
- R语言中的几种数据结构
R语言中的几种数据结构 一 R中对象的5种基本类型 字符(character) 整数 (integer) 复数(complex) 逻辑(logical:True/False) 数值(numeric: ...
- MySQL 修改密码,
ALTER USER 'root'@'localhost' IDENTIFIED BY 'admin';
- 练习3-python-创造百万条数据库数据
有时候需求大批量的数据做测试支撑,如果使用传统的添加数据的方式可能比较耗费时间,利用python可以轻松的完成这项任务,还可以后续维护使用脚本. 方法1:insert into table selec ...
- ElasticSearch 基础 1
ElasticSearch 基础=============================== 索引创建 ========================== 1. RESTFUL APIAPI 基本 ...
- python 导入json模块的用法
json用于字符串,和 python数据类型间进行转换,json模块有四个功能,dumps,dump,loads,load. json 用法 json.dumps 将数据通过特殊的形式转换为所有程序语 ...
- Oracle之共享服务器模式
在共享服务器体系结构中,一个dispatcher分派器将传入网络的多个会话请求定向到一个共享服务器进程池,消除了为每个连接分配一个专用服务器进程的需要.作为一般的指导原则,仅当系统需要并发连接到数据库 ...
- 自定义django中间件
自定义中间件 第一步:在根目录创建路径Middle/m1.py(注意如果是python2的话Middle下要有__init__.py文件,不然会报找不到模块错误) m1.py的内容: # -*- co ...
- .NET的优点(转载)
一:什么是.NET?它包括什么? .Net是为简化在第三代因特网的高分布式环境下的应用程序开发,基于开放互联网标准和协议之上,实现异质语言和平台高度交互性,而构建的新一代计算和通信平台. .Net主要 ...
- vue中的scope
在vue文件中的style标签上,有一个特殊的属性:scoped. 当一个style标签拥有scoped属性时,它的CSS样式就只能作用于当前的组件,也就是说,该样式只能适用于当前组件元素. 通过该属 ...
- NodeJS、npm安装步骤和配置(windows版本)
https://jingyan.baidu.com/article/48b37f8dd141b41a646488bc.html 上面这个链接很详细了,怕它没了自己记一遍.我的简洁一点. 1. 打开no ...