/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 4ms 2.02 MiB
#2 Wrong Answer 4ms 2.02 MiB

Code

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int        long long int
#define pb         push_back
#define all(x)     x.begin(),x.end()
#define allr(x)    x.rbegin(),x.rend()
#define ii         pair<int,int>
#define endl       '\n'

template <class T>
using orderedSet =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 5;
vector<int> spf(N);

void precal() {
    for(int i = 1 ; i < N ; i++)
        spf[i] = i;
    for(int i = 2 ; i < N ; i++) {
        if(spf[i] == i) {
            for(int j = i ; j < N ; j += i)
                spf[j] = min(spf[j], i);
        }
    }
}

void pipra(int tc) {
    int n;
    cin >> n;
    vector<int> a(n + 1), ans(n + 1);
    for(int i = 1 ; i <= n ; i++)
        cin >> a[i];
    map<int, vector<int>> m;
    for(int i = 1 ; i <= n ; i++) {
        m[spf[i]].pb(i);
    }

    for(auto [e, v] : m) {
        orderedSet<int> os;
        os.insert(1e6);
        reverse(all(v));
        ans[v[0]] = 1e6;
        if(a[v[0]]) {
            cout << "No\n";
            return;
        }
        for(int i = 1 ; i < v.size() ; i++) {
            if(a[v[i]] > os.size()) {
                cout << "No\n";
                return;
            }
            else if(a[v[i]] == os.size()) {
                int val = *os.find_by_order(0);
                ans[v[i]] = val - n;
                os.insert(val - n);
            }
            else if(a[v[i]] == 0) {
                int val = *os.find_by_order(os.size() - 1);
                ans[v[i]] = val + n;
                os.insert(val + n);
            }
            else {
                int val = *os.find_by_order(a[v[i]]);
                ans[v[i]] = val - 1;
                os.insert(val - 1);
            }
        }
    }
    cout << "YES\n";
    for(int i = 1 ; i <= n ; i++)
        cout << ans[i] << ' ';
    cout << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    precal();
    int t = 1;
    cin >> t;
    for(int i = 1 ; i <= t ; i++)
        pipra(i);
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1163 Roy and Array Construction
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-11 14:59:27
Judged At
2025-04-11 14:59:27
Judged By
Score
0
Total Time
4ms
Peak Memory
2.02 MiB