What's the error? (Codeforces Round #843 -Problem-C)

Правка en1, от Raks_splunk, 2023-01-06 15:44:57

void solve(){ ll n; cin>>n; priority_queue<ll,vector,greater>p; unordered_map<ll,ll>m2; vectorv(n); vectorv1(n); vectorv2(n); vectorf1(n+1); vectorf2(n+1); vectorf3(n+1); for(ll i=0;i<n;i++){ cin>>v[i]; f3[v[i]]++; } for(int i=1;i<=n;i++){ if(f3[i]>1){ m2[i]+=2; } else if(f3[i]==0){ p.push(i); p.push(i); } } for(ll i=0;i<n;i++){ if(f1[v[i]]==0){ v1[i]=v[i]; f1[v[i]]++; if(m2.find(v[i])!=m2.end()){ m2[v[i]]--; ll x=p.top(); p.pop(); v2[i]=x; } } else if(f2[v[i]]==0){ v2[i]=v[i]; f2[v[i]]++; if(m2.find(v[i])!=m2.end()){ m2[v[i]]--; ll x=p.top(); p.pop(); v1[i]=x; } } } for(ll i=0;i<n;i++){ if(v1[i]==0){ v1[i]=v2[i]; } else if(v2[i]==0){ v2[i]=v1[i]; } } for(ll i=0;i<n;i++){ if(max(v1[i],v2[i])!=v[i]){ cout<<"NO"<<nline; return; } } cout<<"YES"<<nline; for(ll i=0;i<n;i++){ cout<<v1[i]<<" "; } cout<<nline; for(ll i=0;i<n;i++){ cout<<v2[i]<<" "; } cout<<nline; } int main(){ int t; cin>>t; while(t--){ solve(); } }AIM Tech Round 4 (Div. 1)

Used min heap priority queue to store the missing numbers from the given array and a map to store the numbers which are repeated more than once.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский Raks_splunk 2023-01-06 15:52:19 2
en2 Английский Raks_splunk 2023-01-06 15:46:34 1611
en1 Английский Raks_splunk 2023-01-06 15:44:57 1829 Initial revision (published)