結果
問題 | No.3101 Range Eratosthenes Query |
ユーザー |
|
提出日時 | 2025-04-11 22:02:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 360 ms / 3,000 ms |
コード長 | 1,164 bytes |
コンパイル時間 | 2,486 ms |
コンパイル使用メモリ | 199,576 KB |
実行使用メモリ | 82,604 KB |
最終ジャッジ日時 | 2025-04-11 22:03:10 |
合計ジャッジ時間 | 11,244 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} #include<atcoder/fenwicktree> const int MAX=1'000'000; void Solve(){ vector<int>V(MAX+1); for(int i=MAX;i>=1;i--){ for(int j=2*i;j<=MAX;j+=i){ if(V[j]==0){ V[j]=i; } } } vector<vector<int>>W(MAX+1); for(int i=1;i<=MAX;i++)W[V[i]].push_back(i); int Q; cin>>Q; vector<int>L(Q),R(Q); for(int i=0;i<Q;i++){ cin>>L[i]>>R[i]; } vector<vector<int>>T(MAX+1); for(int i=0;i<Q;i++)T[L[i]].push_back(i); atcoder::fenwick_tree<int>fw(MAX+1); vector<int>ans(Q); for(int i=0;i<=MAX;i++){ for(auto q:T[i]){ ans[q]=fw.sum(L[q],R[q]+1); } for(auto j:W[i])fw.add(j,1); } for(int i=0;i<Q;i++)cout<<ans[i]<<"\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); Solve(); }