2017CCPC 杭州 J. Master of GCD【差分标记/线段树/GCD】
给你一个n个初始元素都为1的序列和m个询问q。
询问格式为:l r x(x为2or3)
最后求1~n所有数的GCD
GCD:把每个数分别分解质因数,再把各数中的全部公有质因数提取出来连乘,所得的积就是这几个数的最大公约数。
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define mod 998244353
#define pi acos(-1.0)
#define rep(i,x,n) for(int i=(x); i<(n); i++)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 1<<30;
const int maxn = 1e5+3;
const double eps = 1e-8;
const int dx[] = {-1,1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dir[2]={-1,1};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
LL t,n,m;
LL Pow(LL a, LL b)
{
LL res=1;
while(b)
{
if(b&1)
res=(res%mod * a%mod)%mod;
a = a%mod*a%mod;
b>>=1;
}
return res%mod;
}
LL a[maxn],b[maxn];
int main()
{
scanf("%lld",&t);
while(t--)
{
ms(a,0),ms(b,0);
scanf("%lld%lld",&n,&m);
while(m--)
{
LL l,r,x;
scanf("%lld%lld%lld",&l,&r,&x);
if(x==2)
{
a[l]++,a[r+1]--; //差分标记因子含有2的数、区间加维护2or3的操作数
}
else
{
b[l]++,b[r+1]--;
}
}
LL m1=a[1],m2=b[1];
for(int i=2;i<=n;i++)
{
a[i]+=a[i-1]; //前缀和维护序列本身,而序列记录2的操作数即个数,得到具体每个数的操作数
b[i]+=b[i-1];
m1=min(m1,a[i]); //2的最小操作数
m2=min(m2,b[i]);
}
LL ans = (Pow(2,m1)%mod*Pow(3,m2)%mod)%mod;
printf("%lld\n",ans);
}
}
/*
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
【题意】
【类型】
【分析】
【时间复杂度&&优化】
【trick】
【数据】
*/
2017CCPC 杭州 J. Master of GCD【差分标记/线段树/GCD】的更多相关文章
- CSU 2151 集训难度【多标记线段树】
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=2151 Input 第一行三个数n,m,v0 表示有n名萌新和m次调整,初始时全部萌新的集训难度 ...
- Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
- HDU 5029 Relief grain 树链剖分打标记 线段树区间最大值
Relief grain Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- hdu 5381 The sum of gcd(线段树+gcd)
题目链接:hdu 5381 The sum of gcd 将查询离线处理,依照r排序,然后从左向右处理每一个A[i],碰到查询时处理.用线段树维护.每一个节点表示从[l,i]中以l为起始的区间gcd总 ...
- 2018 Arab Collegiate Programming Contest (ACPC 2018) G. Greatest Chicken Dish (线段树+GCD)
题目链接:https://codeforces.com/gym/101991/problem/G 题意:给出 n 个数,q 次询问区间[ li,ri ]之间有多少个 GCD = di 的连续子区间. ...
- Luogu5327【ZJOI2019】语言【树上差分,线段树合并】
题目大意 给定一棵$n$个节点的树,维护$n$个集合,一开始第$i$个集合只有节点$i$.有$m$个操作,每次操作输入一个$(u,v)$,表示将$(u,v)$这条链上所有点所属的集合合并.求有多少个无 ...
- POJ - 2777——Count Color(懒标记线段树二进制)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 53639 Accepted: 16153 Des ...
- HDU 5875 Function (线段树+gcd / 单调栈)
题意:给你一串数a再给你一些区间(lef,rig),求出a[lef]%a[lef+1]...%a[rig] 题解:我们可以发现数字a对数字b取模时:如果a<b,则等于原数,否则a会变小至少一半. ...
- CF914D Bash and a Tough Math Puzzle 线段树+gcd??奇怪而精妙
嗯~~,好题... 用线段树维护区间gcd,按如下法则递归:(记题目中猜测的那个数为x,改动次数为tot) 1.若子区间的gcd是x的倍数,不递归: 2.若子区间的gcd是x的倍数,且没有递归到叶子结 ...
随机推荐
- MySql 利用函数 查询所有子节点
前提:mysql 函数 find_in_set(str,strlist), cast(value as type) 一.find_in_set(str,strlist):如果字符串str是在的 ...
- 2015/9/2 Python基础(7):元组
为什么要创造一个和列表差别不大的容器类型?元组和列表看起来不同的一点是元组用圆括号而列表用方括号.而最重要的是,元组是不可变类型.这就保证了元组的安全性.创造元组给它赋值和列表完全一样.除了一个元素的 ...
- [洛谷P3527] [POI2011]MET-Meteors
洛谷题目链接:[POI2011]MET-Meteors 题意翻译 Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1 ...
- MyBatis框架的使用及源码分析(二) 配置篇 SqlSessionFactoryBuilder,XMLConfigBuilder
在 <MyBatis框架中Mapper映射配置的使用及原理解析(一) 配置与使用> 的demo中看到了SessionFactory的创建过程: SqlSessionFactory sess ...
- iOS 网络请求--- 配置info.plist文件
一.配置info.plist <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitra ...
- Canvas 基本绘图方法总结
一.基本内容 1.简单来说,HTML5提供的新元素<canvas> 2.Canvas在HTML页面提供画布的功能,在画布中绘制各种图形 3.Canvas绘制的图形与HTML页面无关, ...
- spring怎么实现单例模式?
Spring学习之路——单例模式和多例模式 在Spring中,bean可以被定义为两种模式:prototype(多例)和singleton(单例) singleton(单例):只有一个共享的实例存 ...
- 一道lambda表达式题目
#include <iostream> #include <functional> using namespace std; auto Pair = [](auto u, au ...
- 微信小程序滑动选择器
实现微信小程序滑动选择效果 在wxml文件中,用一个picker标签代表选择器,bindchange是用户点击确定后触发的函数,index是picker自带的参数,用户点击确定后,bindchange ...
- RecycleView Bug:java.lang.IndexOutOfBoundsException: Inconsistency detected.
今天使用RecyclerView时,上下两个RecyclerView,在实现下拉刷新时,报错: java.lang.IndexOutOfBoundsException: Inconsistency d ...