题目描述
Hakase has n numbers in a line. At fi rst, they are all equal to 1. Besides, Hakase is interested in primes. She will choose a continuous subsequence [l, r] and a prime parameter x each time and for every l≤i≤r, she will change ai into ai*x. To simplify the problem, x will be 2 or 3. After m operations, Hakase wants to know what is the greatest common divisor of all the numbers.

输入
The first line contains an integer T (1≤T≤10) representing the number of test cases.
For each test case, the fi rst line contains two integers n (1≤n≤100000) and m (1≤m≤100000),where n refers to the length of the whole sequence and m means there are m operations.
The following m lines, each line contains three integers li (1≤li≤n), ri (1≤ri≤n), xi (xi∈{2,3} ),which are referred above.

输出
For each test case, print an integer in one line, representing the greatest common divisor of the sequence. Due to the answer might be very large, print the answer modulo 998244353.

样例输入
2
5 3
1 3 2
3 5 2
1 5 3
6 3
1 2 2
5 6 2
1 6 2
样例输出
6
2

提示
For the first test case, after all operations, the numbers will be [6,6,12,6,6]. So the greatest common divisor is 6.

题目大意是说在一个数列中,每次对给定区间内的数乘二或者乘三,求最后所有数的最大公因数。用到了线段树的区间更新,找到区间中最少的2和最少的3,所有乘积即为答案。

#include<stdio.h>
#include<iostream>
#include<memory.h>
using namespace std;
struct Node{int l,r;long long int num2,num3;long long int lazy2,lazy3;
};
struct Node nodes[100005<<2];
void build(int l,int r,int n)
{nodes[n].l=l;nodes[n].r=r;nodes[n].lazy2=0;nodes[n].lazy3=0;nodes[n].num2=0;nodes[n].num3=0;if(l==r) return;int mid=(l+r)>>1;build(l,mid,n<<1);build(mid+1,r,n<<1|1);
}
void pushdown(int n)
{if(nodes[n].lazy2){nodes[n<<1].lazy2+=nodes[n].lazy2;nodes[n<<1|1].lazy2+=nodes[n].lazy2;nodes[n<<1].num2+=nodes[n].lazy2;nodes[n<<1|1].num2+=nodes[n].lazy2;nodes[n].lazy2=0;}if(nodes[n].lazy3){nodes[n<<1].lazy3+=nodes[n].lazy3;nodes[n<<1|1].lazy3+=nodes[n].lazy3;nodes[n<<1].num3+=nodes[n].lazy3;nodes[n<<1|1].num3+=nodes[n].lazy3;nodes[n].lazy3=0;}
}
void update(int l,int r,int x,int n)
{if(l<=nodes[n].l&&r>=nodes[n].r){if(x==2){nodes[n].lazy2++;nodes[n].num2++;}if(x==3){nodes[n].lazy3++;nodes[n].num3++;}return;}pushdown(n);int mid=(nodes[n].l+nodes[n].r)>>1;if(l<=mid) update(l,r,x,n<<1);if(r>mid) update(l,r,x,n<<1|1);nodes[n].num2=min(nodes[n<<1].num2,nodes[n<<1|1].num2);nodes[n].num3=min(nodes[n<<1].num3,nodes[n<<1|1].num3);
}
int main()
{int t;scanf("%d",&t);while(t--){int n,m;scanf("%d%d",&n,&m);build(1,n,1);for(int i=0;i<m;i++){int l,r,x;scanf("%d%d%d",&l,&r,&x);update(l,r,x,1);} long long int ans=1;for(long long int i=0;i<nodes[1].num2;i++)ans=ans*2%998244353;for(long long int i=0;i<nodes[1].num3;i++)ans=ans*3%998244353;printf("%lld\n",ans);} return 0;
}

Master of GCD 线段树区间更新相关推荐

  1. hdu 5692 Snacks(dfs序+线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5692 解题思路:这道题是树节点的点权更新,而且涉及到子树,常用的思路是利用dfs序,用线段树来对区间进 ...

  2. hdu 1698(线段树区间更新)

    解题思路:线段树区间更新水题. #include<iostream> #include<cstdio> #include<cstring> using namesp ...

  3. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  4. hdu 3966(树链剖分+线段树区间更新)

    传送门:Problem 3966 https://www.cnblogs.com/violet-acmer/p/9711441.html 学习资料: [1]线段树区间更新:https://blog.c ...

  5. POJ 2777 ZOJ 1610 HDU 1698 --线段树--区间更新

    直接将这3题 放一起了  今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 ...

  6. Just a Hook(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 In the game of DotA, Pudge's meat hook is actual ...

  7. hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新

    #1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,"模拟都市"是他们非常喜欢的一个游戏 ...

  8. CodeForces - 272C Dima and Staircase (线段树区间更新)

    题意: 见以下样例,给出 5 个区间,每个区间的高度已知.一共 4 次操作.每次操作都是从最左边开始向下垒一个宽为 w 高为h 的木块,过程见下图. 问每次垒木块的高度是多少? Input 5 1 2 ...

  9. CDOJ-1057 秋实大哥与花(线段树区间更新)

    秋实大哥与花 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit St ...

最新文章

  1. Lync 小技巧-49-Lync 自动备份-批量管理-用户(免费视频)
  2. python无法启动该程序因为计算机中丢失_python报错:无法启动此程序,因为计算机中丢失...
  3. python中axis是什么意思_Python axis的含义
  4. PAT甲级1087 All Roads Lead to Rome (30分):[C++题解]dijkstra求单源最短路综合、最短路条数、保存路径
  5. 云图说|高效管理华为云SAP的“秘密武器”
  6. vector与list的接口介绍与如何使用以及区别,附代码。
  7. jvm内存模型_JVM|02内存模型
  8. 科大讯飞离线语音识别安装与运行
  9. java核心技术.pdf
  10. 刷屏的北京雾霾,2018 年北上广深空气质量分析
  11. 【蓝桥杯Java组】数论基础—素数筛、最大公约数、最小公倍数
  12. 联想小新校园活动推广策划案
  13. Android技巧之相对高度使用
  14. java开发设置用户头像_如何修改 WordPress 的用户默认头像?
  15. vscode配置c/c++编译环境(最终解决办法)
  16. 微信小程序实现保存图片(唤起用户授权)
  17. 光照相关 shader
  18. [office2010]受保护的视图如何找到源头
  19. Pycharm设置http代理
  20. 打破日韩垄断,研发国产8K传感器芯片的长光辰芯是什么来头?

热门文章

  1. ISO七层参考模型, TCP/IP
  2. 修改Google toolbar for firefox的默认语言
  3. dubbo源码-服务发现
  4. scrapy.Request使用meta传递数据,以及deepcopy的使用
  5. 【Tomcat】Tomcat下设置项目为默认项目
  6. linux下简单限制网卡速度
  7. [转]Spring中的ContextLoaderListener使用
  8. Eclipse中使用Junit编写测试用例
  9. REST API之前端跨域访问
  10. 程序出错后 程序员给测试人员的20条高频回复