QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#456088 | #4831. Eager Sorting | biank23 | 0 | 0ms | 0kb | C++14 | 1.9kb | 2024-06-27 10:17:54 | 2024-06-27 10:17:56 |
answer
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define all(x) begin(x),end(x)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define dforsn(i,s,n) for(int i=int(n)-1;i>=int(s);i--)
#define dforn(i,n) for(int i=int(n)-1;i>=0;i--)
#define dbg(x) cerr<<#x<<": "<<x<<endl
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
//const int MAXN = 2e5+5;
//const ll INF = 1e18;
const int MOD = 1e9+7;
template<class x> ostream & operator<<(ostream & out, vector<x> v){
out<<"[ ";
for(auto y : v) out<<y<<" ";
out<<"]";
return out;
}
template<class a, class b> ostream & operator<<(ostream & out, pair<a, b> p){
return out<<"("<<p.fst<<", "<<p.snd<<")";
}
vi p,p2;
bool cmp(int x, int y){//x<y
cout<<x<<' '<<y<<endl;
int r; cin>>r;
if(r==-1)exit(0);
if(r==1){
swap(p[x],p[y]);
p2[p[x]]=x,p2[p[y]]=y;
return false;
}
return true;
}
vi merge(const vi &a, const vi &b){
int n=sz(a),m=sz(b);
vi c(n+m);
int i=0,j=0;
forn(k,n+m){
if(j>=m||(i<n&&cmp(a[i],b[j]))) c[k]=a[i++];
else c[k]=b[j++];
}
return c;
}
void merge_sort(vi &v){
int n=sz(v);
if(n<=1) return;
vi a(begin(v),begin(v)+n/2);
vi b(begin(v)+n/2,end(v));
merge_sort(a);
merge_sort(b);
v=merge(a,b);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin>>n;
vi a(n); forn(i,n) cin>>a[i];
p.resize(n); iota(all(p),0);
p2.resize(n); iota(all(p2),0);
merge_sort(a);
forn(i,n) cmp(p2[i],p[a[i]]);
cout<<"-1 -1"<<endl;
return 0;
}
詳細信息
Test #1:
score: 0
Instance #0 Time Limit Exceeded
Interactor to First Run
5
First Run to Interactor
Interactor to Second Run
Second Run to Interactor
Manager to Checker
WA Invalid Operation -1672114984 21930