Submission #3391836
Source Code Expand
#include <iostream> #include <unordered_map> #include <vector> #include <math.h> #define llint long long #define mod 1000000007 #define inf 1e18 using namespace std; typedef unordered_map<llint, llint> UMP; llint N, Q; llint x[100005]; llint prime[100005]; UMP mp[100005]; UMP blk[1005]; 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 = 0; i < N; i++) cin >> x[i]; llint B = sqrt(N), Bnum = (N+B-1)/B; for(int i = 0; i < N; i++){ for(auto it = mp[x[i]].begin(); it != mp[x[i]].end(); it++){ blk[i/B][it->first] += it->second; } } /*for(int i = 0; i < Bnum; i++){ cout << blk[i].size() << endl; }*/ llint l, r; for(int q = 0; q < Q; q++){ cin >> l >> r; l--, r--; UMP tmp; llint ll = (l+B-1)/B*B, rr = r/B*B; //cout << ll << rr << endl; if(ll <= rr){ for(int i = ll/B; i < rr/B; i++){ for(auto it = blk[i].begin(); it != blk[i].end(); it++){ tmp[it->first] += it->second; } } for(int i = l; i < ll; i++){ for(auto it = mp[x[i]].begin(); it != mp[x[i]].end(); it++){ tmp[it->first] += it->second; } } for(int i = rr; i < min(N, r+1); i++){ for(auto it = mp[x[i]].begin(); it != mp[x[i]].end(); it++){ tmp[it->first] += it->second; } } } else{ for(int i = l; i <= r; i++){ for(auto it = mp[x[i]].begin(); it != mp[x[i]].end(); it++){ tmp[it->first] += it->second; } } } llint ans = 1; for(auto it = tmp.begin(); it != tmp.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 | 1878 Byte |
Status | TLE |
Exec Time | 2657 ms |
Memory | 26088 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 | TLE | 2656 ms | 24164 KB |
02.txt | TLE | 2656 ms | 26088 KB |
03.txt | TLE | 2657 ms | 24656 KB |
04.txt | TLE | 2656 ms | 24668 KB |
05.txt | TLE | 2656 ms | 21888 KB |
06.txt | TLE | 2656 ms | 21888 KB |
07.txt | TLE | 2656 ms | 21248 KB |
08.txt | TLE | 2656 ms | 21248 KB |
09.txt | TLE | 2656 ms | 24412 KB |
10.txt | TLE | 2657 ms | 24440 KB |
11.txt | AC | 1869 ms | 21248 KB |
12.txt | AC | 1370 ms | 21248 KB |
13.txt | AC | 1144 ms | 20992 KB |
14.txt | AC | 891 ms | 20864 KB |
15.txt | AC | 1151 ms | 21120 KB |
16.txt | AC | 894 ms | 20992 KB |
17.txt | TLE | 2656 ms | 20992 KB |
18.txt | TLE | 2656 ms | 20992 KB |
19.txt | TLE | 2656 ms | 20864 KB |
20.txt | TLE | 2656 ms | 21120 KB |
21.txt | TLE | 2656 ms | 21248 KB |
22.txt | AC | 1908 ms | 21248 KB |
s1.txt | AC | 45 ms | 19456 KB |
s2.txt | AC | 45 ms | 19456 KB |