/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 18ms 576.0 KiB
#5 Accepted 75ms 1.137 MiB
#6 Accepted 432ms 12.098 MiB
#7 Accepted 616ms 45.895 MiB
#8 Accepted 396ms 45.898 MiB
#9 Accepted 373ms 46.023 MiB
#10 Accepted 558ms 46.133 MiB
#11 Accepted 376ms 19.949 MiB
#12 Accepted 347ms 7.332 MiB
#13 Accepted 111ms 1.781 MiB
#14 Accepted 96ms 1.391 MiB
#15 Accepted 67ms 28.93 MiB
#16 Accepted 378ms 45.98 MiB
#17 Accepted 461ms 45.949 MiB
#18 Accepted 178ms 2.824 MiB
#19 Accepted 194ms 3.344 MiB
#20 Accepted 246ms 7.402 MiB

Code

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define repeat(x) for(int taramtam = 0;taramtam<(x);taramtam++)
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
template<typename S, typename T> void semax(S &a, const T &b) {if (a<b) a = b;}
template<typename S, typename T> void semin(S &a, const T &b) {if (a>b) a = b;}

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H;dbg_out(T...);}
#define debug(...) cerr << "(" #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const int INF = 1e9+100;
const int MOD = 1e9+7;

#define int long long
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename S>
void displayvec(vector<S> a){
    for (S thing:a){
        cout << thing << ' ';
    }
    cout << '\n';
}
template <typename S> 
void readvec(vector<S>& a){
    for (S& thing:a){
        cin>>thing;
    }
}

void solve(){
    int n;cin>>n;
    int N=n;
    vector<int> lp(N+1);
    vector<int> pr;
    lp[1]=1;
    for (int i=2; i <= N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back(i);
        }
        for (int j = 0; i * pr[j] <= N; ++j) {
            lp[i * pr[j]] = pr[j];
            if (pr[j] == lp[i]) {
                break;
            }
        }
    }
    vector<int> c(n);
    readvec(c);
    vector<int> a(n);
    bool abr=true;
    vector<vector<int>> nbg(n+1);
    for(int i = 0;i<n;i++){
        int group = lp[i+1];
        int bt = c[i];
        nbg[group].push_back(i);
    }
    for(auto thing:nbg){
        ordered_set things;
        for(int i = 1;i<=thing.size();i++){
            things.insert(i);
        }
        for(auto thing2:thing){
            int ord = c[thing2];
            auto x = things.find_by_order(ord);
            if (x==things.end()){
                abr=false;
                break;
            }
            a[thing2]=*x;
            things.erase(*x);
        }
        if(!abr)break;
    }
    cout << (abr ? "Yes" : "No") << '\n';
    if (abr){
        displayvec(a);
    }
}







signed main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    //freopen("compin.txt", "r", stdin);
	//freopen("compout.txt", "w", stdout);
    int TestCase = 1;
    cin >> TestCase;
    while(TestCase--) solve();
}

Information

Submit By
Type
Submission
Problem
P1163 Roy and Array Construction
Contest
Brain Booster #8
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 15:52:36
Judged At
2025-02-17 15:52:36
Judged By
Score
100
Total Time
616ms
Peak Memory
46.133 MiB