Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)E. Petya and Construction Set(pair操作构造)

https://codeforc.es/contest/1214/problem/E

借鉴自dls的做法:先把奇数号从长到短连接起来然后连剩下的偶数号。

 1 #define bug(x) cout<<#x<<" is "<<x<<endl
 2 #define IO std::ios::sync_with_stdio(0)
 3 #include <bits/stdc++.h>
 4 #define iter ::iterator
 5 #define pa pair<int,int>
 6 using namespace  std;
 7 #define ll long long
 8 #define mk make_pair
 9 #define pb push_back
10 #define se second
11 #define fi first
12 #define ls o<<1
13 #define rs o<<1|1
14 ll mod=998244353;
15 const int N=2e5+5;
16 int n;
17 pa p[N];
18 vector<pa>ans;
19 int pos[N];
20 int main(){
21     IO;
22     cin>>n;
23     for(int i=1;i<=n;i++){
24         cin>>p[i].fi;
25         p[i].se=i;
26     }
27     sort(p+1,p+1+n);
28     reverse(p+1,p+1+n);
29     for(int i=1;i<=n;i++){
30         pos[i]=p[i].se*2-1;
31         if(i>1){
32             ans.pb(mk(pos[i-1],pos[i]));
33         } 
34     }
35     int len=n;
36     for(int i=1;i<=n;i++){
37         int c=i+p[i].fi;
38         if(c==len+1){
39             pos[c]=p[i].se*2;
40             ans.pb(mk(pos[c-1],pos[c]));
41             len++;
42         }
43         else{
44             ans.pb(mk(pos[c-1],2*p[i].se));
45         }
46     }
47     for(auto p: ans){
48         cout<<p.fi<<" "<<p.se<<endl;
49     }
50 }

猜你喜欢

转载自www.cnblogs.com/ccsu-kid/p/11469061.html