Submission #3391686
Source Code Expand
#include <iostream>
#include <unordered_map>
#include <vector>
#define llint long long
#define mod 1000000007
#define inf 1e18
using namespace std;
typedef unordered_map<llint, llint> UMP;
struct SegTree{
int size;
vector<UMP> seg;
SegTree(){}
SegTree(int size){
this->size = size;
seg.resize(1<<(size+1));
}
void set(int i, UMP ump)
{
seg[(1<<size)+i] = ump;
}
void build()
{
for(int i = (1<<size)-1; i >= 1; i--){
UMP lval = seg[i*2], rval = seg[i*2+1];
for(auto it = rval.begin(); it != rval.end(); it++){
lval[it->first] += it->second;
}
seg[i] = lval;
}
}
UMP query(int a, int b, int k, int l, int r)
{
if(b < l || r < a) return UMP();
if(a <= l && r <= b) return seg[k];
UMP lval = query(a, b, k*2, l, (l+r)/2);
UMP rval = query(a, b, k*2+1, (l+r)/2+1, r);
if(lval.size() < rval.size()) swap(lval, rval);
for(auto it = rval.begin(); it != rval.end(); it++){
lval[it->first] += it->second;
}
return lval;
}
UMP query(int a, int b)
{
return query(a, b, 1, 0, (1<<size)-1);
}
};
llint N, Q;
llint x[100005];
llint prime[100005];
UMP mp[100005];
SegTree seg(100005);
int main(void)
{
for(int i = 2; i < 1005; i++){
if(prime[i]) continue;
for(int j = 2*i; j < 100005; j+=i) prime[j] = i;
}
for(int i = 2; i < 100005; i++){
llint x = i;
while(prime[x]){
mp[i][prime[x]]++;
x /= prime[x];
}
if(x > 1) mp[i][x]++;
}
cin >> N >> Q;
for(int i = 1; i <= N; i++) cin >> x[i];
for(int i = 1; i <= N; i++) seg.set(i, mp[x[i]]);
seg.build();
llint l, r; UMP res;
for(int q = 0; q < Q; q++){
cin >> l >> r;
res = seg.query(l, r);
llint ans = 1;
for(auto it = res.begin(); it != res.end(); it++){
ans *= it->second + 1;
ans %= mod;
}
cout << ans << endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
B - ニワンゴくんの約数 |
User |
leaf1415 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1885 Byte |
Status |
RE |
Exec Time |
177 ms |
Memory |
22272 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 1100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, s1.txt, s2.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
RE |
177 ms |
20224 KB |
02.txt |
RE |
164 ms |
20224 KB |
03.txt |
RE |
166 ms |
20224 KB |
04.txt |
RE |
165 ms |
22272 KB |
05.txt |
RE |
163 ms |
20224 KB |
06.txt |
RE |
163 ms |
20224 KB |
07.txt |
RE |
163 ms |
20224 KB |
08.txt |
RE |
163 ms |
20224 KB |
09.txt |
RE |
162 ms |
20224 KB |
10.txt |
RE |
161 ms |
20224 KB |
11.txt |
RE |
166 ms |
20224 KB |
12.txt |
RE |
165 ms |
20224 KB |
13.txt |
RE |
163 ms |
20224 KB |
14.txt |
RE |
163 ms |
20224 KB |
15.txt |
RE |
163 ms |
20224 KB |
16.txt |
RE |
163 ms |
20224 KB |
17.txt |
RE |
163 ms |
20224 KB |
18.txt |
RE |
165 ms |
20224 KB |
19.txt |
RE |
163 ms |
20224 KB |
20.txt |
RE |
162 ms |
20224 KB |
21.txt |
RE |
165 ms |
20224 KB |
22.txt |
RE |
165 ms |
20224 KB |
s1.txt |
RE |
136 ms |
19456 KB |
s2.txt |
RE |
136 ms |
19456 KB |