Please, another Queries on Array?

利用欧拉函数的计算方法, 用线段树搞一搞就好啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long longusing namespace std;const int N = 4e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);int n, q, tot, b[N], prime[301], mul[301];
LL S[301];
char op[20];bool ok(int x) {for(int i = 2; i * i <= x; i++)if(x % i == 0) return false;return true;
}int Power(int a, int b) {int ans = 1;while(b) {if(b & 1) ans = 1ll * ans * a % mod;a = 1ll * a * a % mod; b >>= 1;}return ans;
}int a[N << 2], lazy[N << 2];
LL mask[N << 2], mlazy[N << 2];#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1inline void pull(int rt) {a[rt] = 1ll * a[rt << 1] * a[rt << 1 | 1] % mod;mask[rt] = mask[rt << 1] | mask[rt << 1 | 1];
}void push(int rt, int l, int mid, int r) {if(lazy[rt] != 1) {a[rt << 1] = 1ll * a[rt << 1] * Power(lazy[rt], mid - l + 1) % mod;a[rt << 1 | 1] = 1ll * a[rt << 1 | 1] * Power(lazy[rt], r - mid) % mod;lazy[rt << 1] = 1ll * lazy[rt << 1] * lazy[rt] % mod;lazy[rt << 1 | 1] = 1ll * lazy[rt << 1 | 1] * lazy[rt] % mod;lazy[rt] = 1;}if(mlazy[rt] != 0) {mask[rt << 1] |= mlazy[rt]; mask[rt << 1 | 1] |= mlazy[rt];mlazy[rt << 1] |= mlazy[rt]; mlazy[rt << 1 | 1] |= mlazy[rt];mlazy[rt] = 0;}
}void build(int l, int r, int rt) {lazy[rt] = 1;mlazy[rt] = 0;if(l == r) {a[rt] = b[l];mask[rt] = S[b[l]];return;}int mid = l + r >> 1;build(lson); build(rson);pull(rt);
}void update(int L, int R, int mul, int l, int r, int rt) {if(l >= L && r <= R) {a[rt] = 1ll * a[rt] * Power(mul, r - l + 1) % mod;lazy[rt] = 1ll * lazy[rt] * mul % mod;mask[rt] |= S[mul];mlazy[rt] |= S[mul];return;}int mid = l + r >> 1;push(rt, l, mid, r);if(L <= mid) update(L, R, mul, lson);if(R > mid) update(L, R, mul, rson);pull(rt);
}PLI query(int L, int R, int l, int r, int rt) {if(l >= L && r <= R) return mk(mask[rt], a[rt]);int mid = l + r >> 1;push(rt, l, mid, r);PLI ans = mk(0, 1);if(L <= mid) {PLI tmp = query(L, R, lson);ans.fi |= tmp.fi;ans.se = 1ll * ans.se * tmp.se % mod;}if(R > mid) {PLI tmp = query(L, R, rson);ans.fi |= tmp.fi;ans.se = 1ll * ans.se * tmp.se % mod;}return ans;
}int main() {for(int i = 2; i <= 300; i++)if(ok(i)) prime[tot++] = i;for(int i = 0; i < tot; i++)mul[i] = (1 - Power(prime[i], mod - 2) + mod) % mod;for(int i = 2; i <= 300; i++)for(int j = 0; j < tot && prime[j] <= i; j++)if(i % prime[j] == 0) S[i] |= 1ll << j;scanf("%d%d", &n, &q);for(int i = 1; i <= n; i++) scanf("%d", &b[i]);build(1, n, 1);while(q--) {scanf("%s", op);if(op[0] == 'T') {int L, R; scanf("%d%d", &L, &R);PLI ret = query(L, R, 1, n, 1);int ans = ret.se; LL mask = ret.fi;for(int i = 0; i < tot; i++)if(mask >> i & 1) ans = 1ll * ans * mul[i] % mod;printf("%d\n", ans);} else {int L, R, x;scanf("%d%d%d", &L, &R, &x);update(L, R, x, 1, n, 1);}}return 0;
}/*
*/

转载于:https://www.cnblogs.com/CJLHY/p/10476255.html

Codeforces 1114F Please, another Queries on Array? 线段树相关推荐

  1. Codeforces Round #538 (Div. 2) F. Please, another Queries on Array? 线段树 + 欧拉函数

    传送门 文章目录 题意: 思路: 题意: 给你一个序列aaa,你需要实现两种操作: (1)(1)(1) 将[l,r][l,r][l,r]的aia_iai​都乘rrr. (2)(2)(2) 求ϕ(∏i= ...

  2. Codeforces 671C Ultimate Weirdness of an Array 线段树 (看题解)

    Ultimate Weirdness of an Array 写不出来, 日常好菜啊.. 考虑枚举GCD, 算出一共有多少个对 f(l, r) <= GCD, 我们用fuc[ i ] 表示的是在 ...

  3. CodeForces - 1401 F Reverse and Swap(线段树, 区间翻转, 区间交换,清晰易懂)

    CodeForces - 1401 F Reverse and Swap(线段树, 区间翻转, 区间交换)   首先一共有四个操作,第一个和第四个都是线段树的基本操作,直接用线段树实现.      第 ...

  4. CodeForces - 1539F Strange Array(线段树区间合并)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的序列,规定位置 iii 的贡献是:设 x=a[i]x=a[i]x=a[i],选择一个包含 iii 的区间 [l,r][l,r][l,r],将其中 ...

  5. Educational Codeforces Round 37-F.SUM and REPLACE (线段树,线性筛,收敛函数)

    F. SUM and REPLACE time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...

  6. SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并

    Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...

  7. Codeforces 671E Organizing a Race (贪心、线段树)

    题目链接 https://codeforces.com/contest/671/problem/E 题解 完全不会做--基本是抄lk的代码 ruogu的题解: https://www.luogu.co ...

  8. Codeforces.666E.Forensic Examination(广义后缀自动机 线段树合并)

    题目链接 \(Description\) 给定串\(S\)和\(m\)个串\(T_i\).\(Q\)次询问,每次询问\(l,r,p_l,p_r\),求\(S[p_l\sim p_r]\)在\(T_l\ ...

  9. Codeforces 1089K King Kog's Reception(线段树)

    题目链接:https://codeforces.com/contest/1089/problem/K 题意: 有一些骑士要去见国王,公主也要见国王 给你q个询问,询问有三种操作, 1.+ t d 表示 ...

最新文章

  1. 炫彩流光按钮 html+css
  2. 深度操作系统 15 Beta——每一处都在“靓”变
  3. 【Flutter】HTTP 网络操作 ( 引入 http 插件 | 测试网站 | Get 请求 | Post 请求 | 将响应结果转为 Dart 对象 | Future 异步调用 )
  4. Linux下Shell脚本实战之监测磁盘空间
  5. vue2.0 仿手机新闻站(七)过滤器、动画效果
  6. vs code linux opencv,ubuntu+vscode 测试运行opencv
  7. 64 装饰器函数: 母版 csrf防御机制 cookie
  8. 大数据计算引擎:impala对比hive
  9. 13penrose广义逆矩阵(I)
  10. matlab d函数,matlab常用函数大集合
  11. 【量化数据分析】Amos拟合优度与假设检验
  12. libFetion『Linux下都飞信』
  13. pwm占空比的c语言编程详解,灵动微MM32F003硬件最小系统 --- PWM占空比从0%到100%例程解析【18】...
  14. linux中无损gpt转mbr,如何快速实现免重装无损磁盘MBR转GPT?
  15. NDK crash分析方法
  16. python 分布式框架_Python 并行分布式框架:Celery 超详细介绍
  17. uts大学计算机排名,uts是什么大学
  18. 禁用计算机服务,win7系统禁用不需要服务的操作方法
  19. 数字滤波算法 在数字信号处理应用中使用微控制器
  20. python使用statsmodels包中的tsa.acf函数计算时间序列数据所有滞后位置个数(级别)的自相关性(autocorrelation for every lag)

热门文章

  1. 2017-2018-1 20155229 实验五 《通讯协议设计》
  2. lenovo Win10 安装 Androd Studio 新版本编程开发的软件
  3. Ubuntu 16.04 LTS 安装Mongodb 3.4
  4. IOS --xcode删除Provisioning Profiles文件
  5. windows多线程详解
  6. 《北京IT报道》你可以成为下一个《万万没有想到》?
  7. iOS6兼容之前版本的旋屏总结
  8. OpenCV中的内存泄露问题(cvLoadImage,cvCloneImage)【转】
  9. bum报文_Vxlan学习笔记——原理
  10. lsof查找放进linux回收站中的删除文件,并彻底删除或恢复文件