-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCF1407C.cpp
More file actions
78 lines (67 loc) · 1.45 KB
/
CF1407C.cpp
File metadata and controls
78 lines (67 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<bits/stdc++.h>
using namespace std;
#define ll int long long
#define mp make_pair
//#define for(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define N 1000000007
#define pq priority queue
#define pb push_back
#define pf push_front
#define mt make_tuple
#define prec(a) fixed<<setprecision(9)<<a
//#define endl "\n"
#define fast_set s.max_load_factor(0.25);s.reserve(500);
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
const long double PI = (long double)(3.1415926535897932384626433832795);
// Interactive Problem
int main()
{
fast;
int n,i,j;
cin>>n;
set<int>s;
// inserting 1 to n into set.
for(i=1;i<=n;i++)
{
s.insert(i);
}
int arr[n]={0};
// we have atmost 2n queries but this logic solving the problem in 2(n-1) queries.
for(i=1;i<=n-1;i++)
{
// extracting the first two minimum elements from set.
auto it1=s.begin();
auto it2=it1;
it2++;
int a,b;
cout<<"? "<<(*it1)<<" "<<(*it2)<<endl;
cin>>a;
cout<<"? "<<(*it2)<<" "<<(*it1)<<endl;
cin>>b;
if(a<b)
{
arr[(*it2)-1]=b;
s.erase((*it2));
}
else
{
arr[(*it1)-1]=a;
s.erase((*it1));
}
}
arr[(*s.begin())-1]=n;
// output the result.
cout<<"! ";
for(i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
return 0;
}