Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- #define ll long long
- #define OO 2'000'000'000
- #define ull unsigned long long
- #define nl '\n'
- #define sz(x) (ll)(x.size())
- #define all(x) x.begin(),x.end()
- #define rall(s) s.rbegin(), s.rend()
- #define getline(s) getline(cin>>ws,s)
- #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define pi 3.141592653589793
- #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
- #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
- void Fast_IO(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- // freopen("filename.in", "r", stdin);
- // freopen("filename.out", "w", stdout);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
- int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
- const ll N = 2e6+5;
- vector<bool>isPrime(N,1);
- vector<ll>gpf(N);
- vector<ll>primes;
- void sieve(){
- isPrime[0] = isPrime[1] = 0;
- for(ll i = 2; i < N; i++){
- if(isPrime[i]){
- primes.push_back(i);
- for(ll j = i*i; j < N; j+=i){
- isPrime[j] = 0;
- }
- }
- }
- for(auto&p:primes){
- for(ll j = p; j < N; j+=p){
- gpf[j] = p;
- }
- }
- }
- struct Data{
- ll val,idx;
- bool operator<(const Data&other)const{
- return (val<other.val||(val==other.val&&idx>other.idx));
- }
- };
- void solve(){
- ll n,q; cin>>n>>q;
- vector<ll>v(n);
- for(auto&i:v)cin>>i;
- ll cnt = 1;
- vector<ll>time(n);
- priority_queue<Data>pq;
- for(ll i = 0;i<n;i++){
- pq.push({v[i],i});
- }
- while(!pq.empty()){
- auto cur = pq.top();
- pq.pop();
- cout<<cur.val<<" "<<cur.idx<<nl;
- time[cur.idx] = cnt;
- cur.val/=gpf[cur.val];
- if(cur.val>1)pq.push(cur);
- cnt++;
- }
- for(auto&i:time) cout<<i<<" ";
- cout<<nl;
- }
- int main(){
- Fast_IO();
- sieve();
- int t =1;
- //cin>>t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement