CF594D REQ [离线+树状数组,欧拉函数]
设
\]
那么显然
{\prod_{i=1}^{cnt}p_i}\]
因为每个质数只会出现一次,所以当成数颜色,同 [HH的项链],这题就没了
// powered by c++11
// by Isaunoya
#include <bits/stdc++.h>
#define rep(i, x, y) for (register int i = (x); i <= (y); ++i)
#define Rep(i, x, y) for (register int i = (x); i >= (y); --i)
using namespace std;
using db = double;
using ll = long long;
using uint = unsigned int;
#define int long long
using pii = pair<int, int>;
#define ve vector
#define Tp template
#define all(v) v.begin(), v.end()
#define sz(v) ((int)v.size())
#define pb emplace_back
#define fir first
#define sec second
// the cmin && cmax
Tp<class T> void cmax(T& x, const T& y) {
if (x < y) x = y;
}
Tp<class T> void cmin(T& x, const T& y) {
if (x > y) x = y;
}
// sort , unique , reverse
Tp<class T> void sort(ve<T>& v) { sort(all(v)); }
Tp<class T> void unique(ve<T>& v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
Tp<class T> void reverse(ve<T>& v) { reverse(all(v)); }
const int SZ = 0x191981;
struct FILEIN {
~FILEIN() {}
char qwq[SZ], *S = qwq, *T = qwq, ch;
char GETC() { return (S == T) && (T = (S = qwq) + fread(qwq, 1, SZ, stdin), S == T) ? EOF : *S++; }
FILEIN& operator>>(char& c) {
while (isspace(c = GETC()))
;
return *this;
}
FILEIN& operator>>(string& s) {
while (isspace(ch = GETC()))
;
s = ch;
while (!isspace(ch = GETC())) s += ch;
return *this;
}
Tp<class T> void read(T& x) {
bool sign = 1;
while ((ch = GETC()) < 0x30)
if (ch == 0x2d) sign = 0;
x = (ch ^ 0x30);
while ((ch = GETC()) > 0x2f) x = x * 0xa + (ch ^ 0x30);
x = sign ? x : -x;
}
FILEIN& operator>>(int& x) { return read(x), *this; }
FILEIN& operator>>(signed& x) { return read(x), *this; }
FILEIN& operator>>(unsigned& x) { return read(x), *this; }
} in;
struct FILEOUT {
const static int LIMIT = 0x114514;
char quq[SZ], ST[0x114];
signed sz, O;
~FILEOUT() { flush(); }
void flush() {
fwrite(quq, 1, O, stdout);
fflush(stdout);
O = 0;
}
FILEOUT& operator<<(char c) { return quq[O++] = c, *this; }
FILEOUT& operator<<(string str) {
if (O > LIMIT) flush();
for (char c : str) quq[O++] = c;
return *this;
}
Tp<class T> void write(T x) {
if (O > LIMIT) flush();
if (x < 0) {
quq[O++] = 0x2d;
x = -x;
}
do {
ST[++sz] = x % 0xa ^ 0x30;
x /= 0xa;
} while (x);
while (sz) quq[O++] = ST[sz--];
return;
}
FILEOUT& operator<<(int x) { return write(x), *this; }
FILEOUT& operator<<(signed x) { return write(x), *this; }
FILEOUT& operator<<(unsigned x) { return write(x), *this; }
} out;
int n, q;
const int maxn = 2e5 + 52;
const int maxp = 1e6 + 61;
const int mod = 1e9 + 7;
int a[maxn], las[maxp];
inline int qpow(int x, int y) {
int res = 1;
for (; y; y >>= 1, x = x * x % mod)
if (y & 1) res = res * x % mod;
return res;
}
inline int inv(int x) { return qpow(x, mod - 2); }
struct BIT {
int c[maxn];
inline int low(int x) { return x & -x; }
inline void upd(int x, int y) {
for (; x <= n; x += low(x)) c[x] = c[x] * y % mod;
}
inline int qry(int x) {
int ans = 1;
for (; x; x ^= low(x)) ans = ans * c[x] % mod;
return ans;
}
} bit;
vector<int> prime[maxp];
vector<pii> v[maxn];
void add(int pos) {
for (auto x : prime[a[pos]]) {
if (las[x]) bit.upd(las[x], x), bit.upd(las[x], inv(x - 1));
bit.upd(pos, inv(x)), bit.upd(pos, x - 1);
las[x] = pos;
}
}
int pre[maxn];
int ans[maxn];
signed main() {
#ifdef _WIN64
freopen("testdata.in", "r", stdin);
#else
ios_base ::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
#endif
// code begin.
in >> n;
int mx = 0;
rep(i, 1, n) in >> a[i], cmax(mx, a[i]);
pre[0] = 1;
rep(i, 1, n) pre[i] = pre[i - 1] * a[i] % mod;
vector<bool> vis(mx + 1, 0);
rep(i, 2, mx) if (!vis[i]) {
prime[i].push_back(i);
for (int j = (i << 1); j <= mx; j += i) prime[j].push_back(i), vis[j] = 1;
}
in >> q;
rep(i, 1, q) {
int l, r;
in >> l >> r;
v[r].push_back({ l, i });
}
rep(i, 0, n) bit.c[i] = 1;
rep(i, 1, n) {
add(i);
for (auto x : v[i])
ans[x.second] =
pre[i] * inv(pre[x.first - 1]) % mod * bit.qry(i) % mod * inv(bit.qry(x.first - 1)) % mod;
}
rep(i, 1, q) out << ans[i] << '\n';
return 0;
// code end.
}
CF594D REQ [离线+树状数组,欧拉函数]的更多相关文章
- POJ 3416 Crossing --离线+树状数组
题意: 给一些平面上的点,然后给一些查询(x,y),即以(x,y)为原点建立坐标系,一个人拿走第I,III象限的点,另一个人拿II,IV象限的,点不会在任何一个查询的坐标轴上,问每次两人的点数差为多少 ...
- HDU 2852 KiKi's K-Number(离线+树状数组)
题目链接 省赛训练赛上一题,貌似不难啊.当初,没做出.离线+树状数组+二分. #include <cstdio> #include <cstring> #include < ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组
题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)
转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...
- HDU3333 Turing Tree 离线树状数组
题意:统计一段区间内不同的数的和 分析:排序查询区间,离线树状数组 #include <cstdio> #include <cmath> #include <cstrin ...
- 离线树状数组 hihocoder 1391 Countries
官方题解: // 离线树状数组 hihocoder 1391 Countries #include <iostream> #include <cstdio> #include ...
- 13年山东省赛 Boring Counting(离线树状数组or主席树+二分or划分树+二分)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 2224: Boring Counting Time Limit: 3 Sec ...
- 区间的关系的计数 HDU 4638 离线+树状数组
题目大意:给你n个人,每个人都有一个id,有m个询问,每次询问一个区间[l,r],问该区间内部有多少的id是连续的(单独的也算是一个) 思路:做了那么多离线+树状数组的题目,感觉这种东西就是一个模板了 ...
- BZOJ_2743_[HEOI2012]采花_离线+树状数组
BZOJ_2743_[HEOI2012]采花_离线+树状数组 Description 萧芸斓是Z国的公主,平时的一大爱好是采花.今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花 .花园足够大 ...
随机推荐
- FFMPEG结构体分析:AVCodecParameters
/** * This struct describes the properties of an encoded stream. * * sizeof(AVCodecParameters) is no ...
- HDU_1035_水
http://acm.xidian.edu.cn/problem.php?id=1035 本来想用goto优化一下的,不知道什么情况,加了goto就wa了. #include<iostream& ...
- HDU 6274 Master of Sequence (暴力+下整除)
题意 两个1e5的数组a,b,定义\(S(t)=\left \lfloor \frac{t-b_i}{a_i} \right \rfloor\),有三个操作 1 x y:将\(a[x]\)变为\(y\ ...
- PTA 7-9 集合相似度(STL之set初体验)
7-9 集合相似度(25 分) 给定两个整数集合,它们的相似度定义为:Nc/Nt×100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你 ...
- Ops: 高效组合命令集合
简介 本篇博客收集一些常用的复杂命令组合,这些命令组合能够高效的定位.分析.处理一些问题,希望对需要的小伙伴有所帮助. 命令集合 批量备份文件 将名称为config.xml的文件查找出来,并在原目录备 ...
- bootstrap 表单类
bootstrap 表单类 表单美化 用法: 向父元素 <form role="form"></form> 添加 role="form&q ...
- 第3章 JDK并发包(二)
3.1.2 重入锁的好搭档:Condition条件 它和wait()和notify()方法的作用是大致相同的.但是wait()和notify()方法是和synchronized关键字合作使用的,而Co ...
- 2.5D(伪3D)站点可视化第一弹
楔子 最近要做一个基站站点的可视化呈现项目. 我们首先尝试的是三维的可视化技术来程序,但是客户反馈的情况是他们的客户端电脑比较差,性能效率都会不好,甚至有的还是云主机. 因此我们先做了一个性能比较极致 ...
- DOCKER绝对领域从2048到4069?不:25519,数字的飞跃,HTTP/2
这个标题花了几分钟,远远超过我构思以下内容的时间损耗,希望大家且看且珍惜,因为这是为数不多的cnblog特别标题 我记得很久以前,我开了一系列随笔,从第一篇揭发233的docker/machine开始 ...
- 几个点认识Nginx服务器
Nginx 其实就是一款轻量级的 Web 服务器.反向代理服务器,由于它的内存占用少,启动极快,高并发能力强,在互联网项目中广泛应用. 那么你可能会问了:“不是说 Nginx 吗?怎么又扯出来一个 W ...