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 ...
随机推荐
- beego 注解路由无效问题分析
问题描述:学习 beego 框架发现注解路由无效,除了不能找到路由外,未见任何异常. 问题解决:将配置文件中的 runmode 更改为 dev 模式. 问题分析: 如果没有设置过 runmode 不会 ...
- st.getParameter() 和request.getAttribute() 区别 https://terryjs.iteye.com/blog/1317610
getParameter 是用来接受用post个get方法传递过来的参数的.getAttribute 必须先setAttribute. (1)request.getParameter() 取得是通过容 ...
- python 正则表达式 re.match
#coding:utf-8 import re #匹配内容:单词+空格+单词+任意字符 #\w 单词字符[A-Za-z0-9_] #(?P<name>...) 分组,除了原有的编号外在指定 ...
- git_01_上传第一个项目至git
前言 Git是一个开源的分布式版本控制系统,可以有效.高速地处理从小到大的项目版本管理.最近在自己研究自动测试,也准备放到git上管理.由于工作中是在已有的代码库拉取.提交代码.自己想要初次建库上传项 ...
- Implement Queue using Stacks(用两个栈实现队列)
来源:https://leetcode.com/problems/implement-queue-using-stacks Implement the following operations of ...
- mysql自动补全功能(只能用于表/列 名)
关键字:mysql自动补全,auto-rehash 注:只能补齐表,列名,使用tab进行补全操作 一.修改my.cnf vi /etc/my.cnf [mysql] auto-rehash #添加au ...
- 使用SSI框架写的简单Demo(查询模块)
在网上看到好多个版本,自己有时间索性就写个Demo记录下整个框架的逻辑流程: 1.首先拷贝整个框架所需要的jar包到WEB-INF/lib包下(这个网上都可以搜到的) 2.配置文件的配置, 2.1.在 ...
- 剑指Offer编程题(Java实现)——替换空格
题目描述 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 解题思路1 在字符串尾部填充任 ...
- 一份完整的 MySQL 开发规范,进大厂必看!
作者:听风 https://www.cnblogs.com/huchong/p/10219318.html 一.数据库命令规范 1.所有数据库对象名称必须使用小写字母并用下划线分割 2.所有数据库对象 ...
- 2019 Multi-University Training Contest 3 - 1006 - Fansblog - 打表 - 暴力
http://acm.hdu.edu.cn/showproblem.php?pid=6608 题意:给一个比较大的质数P(1e14以内),求比它小的最大的质数Q(貌似保证存在的样子,反正我没判不存在) ...