Advertisement
Ahmed_Negm

Untitled

Aug 2nd, 2023
1,195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define OO 2'000'000'000
  8. #define ull unsigned long long
  9. #define nl '\n'
  10. #define sz(x) (ll)(x.size())
  11. #define all(x) x.begin(),x.end()
  12. #define rall(s)  s.rbegin(), s.rend()
  13. #define getline(s) getline(cin>>ws,s)
  14. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  15. #define pi  3.141592653589793
  16. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  17. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  18.  
  19.  
  20. void Fast_IO(){
  21. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  22. // freopen("filename.in", "r", stdin);
  23. // freopen("filename.out", "w", stdout);
  24. #ifndef ONLINE_JUDGE
  25. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. }
  28.  
  29.  
  30.  
  31.  
  32. int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  33. int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  34.  
  35. const ll N = 2e6+5;
  36. vector<bool>isPrime(N,1);
  37. vector<ll>gpf(N);
  38. vector<ll>primes;
  39. void sieve(){
  40.     isPrime[0] = isPrime[1] = 0;
  41.     for(ll i = 2; i < N; i++){
  42.         if(isPrime[i]){
  43.             primes.push_back(i);
  44.             for(ll j = i*i; j < N; j+=i){
  45.                 isPrime[j] = 0;
  46.             }
  47.         }
  48.     }
  49.  
  50.     for(auto&p:primes){
  51.         for(ll j = p; j < N; j+=p){
  52.             gpf[j] = p;
  53.         }
  54.     }
  55.  
  56. }
  57.  
  58. struct Data{
  59.     ll val,idx;
  60.     bool operator<(const Data&other)const{
  61.         return (val<other.val||(val==other.val&&idx>other.idx));
  62.     }
  63. };
  64.  
  65.  
  66. void solve(){
  67.  
  68. ll n,q; cin>>n>>q;
  69. vector<ll>v(n);
  70. for(auto&i:v)cin>>i;
  71. ll cnt = 1;
  72. vector<ll>time(n);
  73.  
  74. priority_queue<Data>pq;
  75.  
  76. for(ll i = 0;i<n;i++){
  77.     pq.push({v[i],i});
  78. }
  79.  
  80. while(!pq.empty()){
  81.     auto cur = pq.top();
  82.     pq.pop();
  83.     cout<<cur.val<<" "<<cur.idx<<nl;
  84.     time[cur.idx] = cnt;
  85.     cur.val/=gpf[cur.val];
  86.     if(cur.val>1)pq.push(cur);
  87.     cnt++;
  88. }
  89.  
  90. for(auto&i:time) cout<<i<<" ";
  91. cout<<nl;
  92.  
  93.  
  94.  
  95. }
  96.  
  97. int main(){
  98.     Fast_IO();
  99.     sieve();
  100. int t =1;
  101. //cin>>t;
  102. while(t--){
  103. solve();
  104. }
  105. return 0;
  106. }  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement