题目链接

思路:针对一个数组的操作,即对一个区间。可以用线段树去进行维护。初始化建树,叶子节点的值为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的更多相关文章

  1. 2016级算法第二次上机-F.ModricWang's Number Theory II

    891 ModricWang's Number Theory II 思路 使得序列的最大公约数不为1,就是大于等于2,就是找到一个大于等于2的数,它能够整除序列中的所有数. 考虑使得一个数d整除数组中 ...

  2. 【BZOJ4026】dC Loves Number Theory 分解质因数+主席树

    [BZOJ4026]dC Loves Number Theory Description  dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源.    给 ...

  3. BZOJ_4026_dC Loves Number Theory _主席树+欧拉函数

    BZOJ_4026_dC Loves Number Theory _主席树+欧拉函数 Description  dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯 竭 ...

  4. 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 ...

  5. [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& ...

  6. 题解-Ehab's REAL Number Theory Problem

    Ehab's REAL Number Theory Problem 前置知识 质数 分解质因数 无向无权图最小环<讲> Ehab's REAL Number Theory Problem/ ...

  7. BZOJ4026: dC Loves Number Theory

    Description  dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯 竭的水题资源.    给定一个长度为 n的正整数序列A,有q次询问,每次询问一段区间内所 ...

  8. PARTITION(number theory) ALSO Explosive number in codewars

    问题出于codewars,简言之:寻找和为一个整数的的不同整数组合.https://en.wikipedia.org/wiki/Partition_(number_theory) 例如:和为6的整数组 ...

  9. 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, ...

  10. 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 ...

随机推荐

  1. shell 比较符号

    if [ 1 -ne 1 ];then...fi这是指当1不等于1时执行then后的语句 -eq:等于-ne:不等于-le:小于等于-ge:大于等于-lt:小于-gt:大于

  2. python nginx+uwsgi+WSGI 处理请求详解

    https://blog.csdn.net/a519640026/article/details/76157976 请求从 Nginx 到 uwsgi 到 django 交互概览 作为python w ...

  3. c语言秋季作业2

    问题 答案 这个作业属于哪个课程 C语言程序设计I 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/8657 我在这 ...

  4. vsphere虚拟化之Active Directory域的创建(一)

    1.搭建环境说明 本机是在Vmware Workstation 12 Pro虚拟软件下进行搭建的. 操作系统版本:Windows Server 2012 R2 简体中文企业版x64. 2.安装完win ...

  5. Git-第一篇认识git,核心对象,常用命令

    1.git一般使用流程 4大核心对象:工作区.暂存区.本地库.远端库. 2.常用命令 1>git init:初始化本地仓库 2>git clone:克隆仓库到指定地方 3>git a ...

  6. python进阶之类的反射

    有应用场景的技术才是有灵魂的技术------>最近同时问我,在python中,给你一个函数或者类的字符串名称,你怎么得到该函数和类,以下结合源码记录我得到的方式: 1.给一个函数的字符串&quo ...

  7. Java8 HashMap详解(转)

    Java8 对 HashMap 进行了一些修改,最大的不同就是利用了红黑树,所以其由 数组+链表+红黑树 组成. 根据 Java7 HashMap 的介绍,我们知道,查找的时候,根据 hash 值我们 ...

  8. 简单易用的leetcode开发测试工具(npm)

    描述 最近在用es6解leetcode,当问题比较复杂时,有可能修正了新的错误,却影响了前面的流程.要用通用的测试工具,却又有杀鸡用牛刀的感觉,所以就写了个简单易用的leetcode开发测试工具,分享 ...

  9. Python中yield和return两者之间区别

    在任何函数都有返回值,一般都是想到return 关键词,在函数生成器中有个关键词 yield 也可以做返回值,在函数没调用之前,是不会输出任何东西的 1,return 用法 def stu(): re ...

  10. SSH简单Demo

    web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="3 ...