Multiply game_线段树
To be a friend of this gay, you have been invented by him to play this interesting game with him. Of course, you need to work out the answers faster than him to get a free lunch, He he…
For each test case, the first line is the length of sequence n (n<=50000), the second line has n numbers, they are the initial n numbers of the sequence a1,a2, …,an,
Then the third line is the number of operation q (q<=50000), from the fourth line to the q+3 line are the description of the q operations. They are the one of the two forms:
0 k1 k2; you need to work out the multiplication of the subsequence from k1 to k2, inclusive. (1<=k1<=k2<=n)
1 k p; the kth number of the sequence has been change to p. (1<=k<=n)
You can assume that all the numbers before and after the replacement are no larger than 1 million.
6
1 2 4 5 6 3
3
0 2 5
1 3 7
0 2 5
420
【题意】给出n个数,进行m次操作,0 x y就是求x到y区间的总乘积,1 x y就是把x的位置上的数改为y
【思路】线段树单点更新问题
#include<iostream>
#include<stdio.h>
#include<queue>
#include<string.h>
#define mod 1000000007
using namespace std;
const int inf=0x7777777;
const int N=+; int n,m;
long long int a[N];
long long int sum[N*];
void build(int k,int l,int r)
{
sum[k]=;
if(l==r)
{
sum[k]=a[l]%mod;
return ;
}
int mid=l+r>>;
build(k*,l,mid);
build(k*+,mid+,r);
sum[k]=sum[k*]*sum[k*+]%mod; }
__int64 query(int k,int l,int r,int x,int y)
{
__int64 res=;
if(x<=l&&y>=r) return sum[k];
int mid=l+r>>;
if(x<=mid) res*=query(k*,l,mid,x,y)%mod;
if(y>mid) res*=query(k*+,mid+,r,x,y)%mod;
return res%mod;
}
void updata(int k,int l,int r,int x,int y)
{
if(l==r)
{
sum[k]=y%mod;
return;
}
//sum[k]=sum[k]/a[x]*y;
int mid=l+r>>;
if(x<=mid) updata(*k,l,mid,x,y);
else updata(*k+,mid+,r,x,y);
sum[k]=sum[k*]*sum[k*+]%mod; }
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int op,x,y;
scanf("%d",&n);
for(int i=; i<=n; i++) scanf("%I64d",&a[i]);
build(,,n);
scanf("%d",&m);
for(int i=; i<=m; i++)
{
scanf("%d%d%d",&op,&x,&y);
if(!op)
{
__int64 ans=query(,,n,x,y);
printf("%I64d\n",ans%mod);
}
else
{
updata(,,n,x,y);
}
}
}
return ;
}
Multiply game_线段树的更多相关文章
- HDU 3074 Multiply game(线段树)
单点更新,更新时先除去 原来的数,因为有去摸,可以用乘上逆元代替. //================================================================ ...
- HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模
Multiply game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 3074 Multiply game(模板级线段树)
离机房关门还有十分钟,这点时间能干些什么?故作沉思地仰望星空,重新捋一下一天的学习进度,或者,砍掉一棵模板级线段树. 纯模板,就是把单点更新,区间求和改为单点更新,区间求积. 1A. #include ...
- HDU3074: Multiply game(线段树单点更新,区间查询)
题目: 传送门 题解:线段树模板题目. 对递归的题目始终理解不好,我的痛啊,在水的题目都要写很长时间. #include <iostream> #include <string.h& ...
- HDU 5475(2015 ICPC上海站网络赛)--- An easy problem(线段树点修改)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5475 Problem Description One day, a useless calculato ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- [java线段树]2015上海邀请赛 D Doom
题意:n个数 m个询问 每个询问[l, r]的和, 再把[l, r]之间所有的数变为平方(模为9223372034707292160LL) 很明显的线段树 看到这个模(LLONG_MAX为922337 ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- hdu 4578 线段树(标记处理)
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others) ...
随机推荐
- Eclipse默认标签TODO,XXX,FIXME和自定义标签[转]
http://www.blogjava.net/Guides/archive/2011/11/14/363686.html Eclipse中的一些特殊的注释技术包括: 1. // TO ...
- 【20160924】GOCVHelper MFC增强算法(4)
//string替换 void string_replace(string & strBig, const string & strsrc, const string & ...
- 深入理解C++的动态绑定和静态绑定【转】
转自:http://blog.csdn.net/chgaowei/article/details/6427731 为了支持c++的多态性,才用了动态绑定和静态绑定.理解他们的区别有助于更好的理解多态性 ...
- 【iOS】Foundation框架 学习笔记
1.数组 OC数组不能存放nil值OC数组只能存放OC对象.不能存放非OC对象类型,比如int.struct.enum等 ====================================== ...
- httpd服务安装
1.配置yum ps:详见YUM源设置篇 2输入yum install httpd -y 进行安装 3安装完成后,重启httpd服务 service httpd restart ...
- iOS开发数据库篇—SQLite常用的函数
iOS开发数据库篇—SQLite常用的函数 一.简单说明 1.打开数据库 int sqlite3_open( const char *filename, // 数据库的文件路径 sqlite3 * ...
- XAF How to: 实现一个WCF Application Server 并配置它的客户端应用
本主题描述了如何实现一个 WCF 中间层应用程序服务器及如何配置 XAF客户端连接到此服务器. 注意 本主题演示可以由解决方案向导自动生成的代码.执行操作时,如果你想要在现有的 XAF 解决方案中实现 ...
- Myeclipse 找不到Convert to maven project选项
https://my.oschina.net/u/2419190/blog/504417 Window > Preferences > General > Capabilities ...
- VRP介绍以及AC初始化配置-06
VRP介绍 VRP:多功能路由平台(Versatile Routing Platform) 角色:网络操作系统 支撑多种设备的软件平台 提供TCP/IP 路由服务 通用路由平台VRP(Versatil ...
- python——协程
由于python中的多线程比较特殊,所以协程的概念就变得尤为珍贵了,对于cpu密集型的操作,使用协程的效率无疑要好过多线程很多.因为协程的创建及其间切换的时间成本要低于线程很多.也因为这一点,很多人说 ...