QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#792255 | #1813. Joy with Permutations | ninjadoggy1234 | RE | 0ms | 0kb | C++23 | 4.2kb | 2024-11-29 08:25:44 | 2024-11-29 08:25:45 |
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR1(i, b) for(int i = 0; i < b; i++)
#define FOR2(i, a, b) for(int i = a; i < b; i++)
#define FOR(...) EXPAND(FOR_SELECT(__VA_ARGS__, FOR2, FOR1)(__VA_ARGS__))
#define FOR_SELECT(_1, _2, _3, NAME, ...) NAME
#define EXPAND(x) x
#define ALL(vec) vec.begin(),vec.end()
#define P(var) std::cerr << #var << ": " << var << "\n"
#define SZ(arr) (int)arr.size()
using namespace std;
template<int D, typename T> struct Vec : vector<Vec<D - 1, T>> { Vec() :Vec(0) {} template<typename U, typename... Args> Vec(U n = U(), Args...args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {} friend ostream& operator<<(ostream& s, const Vec& v) { for (size_t i = 0; i < v.size(); ++i)s << v[i]; return s; } void Fill(const T& x) { for (auto& v : *this)v.Fill(x); } Vec& operator+=(const Vec& o) { FOR(i, this->size())(*this)[i] += o[i]; return *this; } Vec& operator-=(const Vec& o) { FOR(i, this->size())(*this)[i] -= o[i]; return *this; } Vec operator+(const Vec& o)const { Vec r(this->size()); FOR(i, this->size())r[i] = (*this)[i] + o[i]; return r; } Vec operator-(const Vec& o)const { Vec r(this->size()); FOR(i, this->size())r[i] = (*this)[i] - o[i]; return r; } friend istream& operator>>(istream& is, Vec& v) { for (auto& e : v)is >> e; return is; } };
template<typename T> struct Vec<1, T> : vector<T> { Vec() : Vec(0) {} using vector<T>::vector; Vec(initializer_list<T> l) : vector<T>(l) {} void Fill(const T& x) { fill(this->begin(), this->end(), x); } friend ostream& operator<<(ostream& s, const Vec& v) { for (size_t i = 0; i < v.size(); ++i)s << v[i] << " \n"[i == v.size() - 1]; return s; } Vec operator+(const Vec& o)const { Vec r(this->size()); FOR(i, this->size())r[i] = (*this)[i] + o[i]; return r; } Vec operator-(const Vec& o)const { Vec r(this->size()); FOR(i, this->size())r[i] = (*this)[i] - o[i]; return r; } Vec& operator+=(const Vec& o) { FOR(i, this->size())(*this)[i] += o[i]; return *this; } Vec& operator-=(const Vec& o) { FOR(i, this->size())(*this)[i] -= o[i]; return *this; } friend istream& operator>>(istream& s, Vec& v) { for (auto& e : v)s >> e; return s; } };
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
const int oo = 1e9;
int Q(int i, int j, int k) {
i++; j++; k++;
cout << 1 << ' ' << i << ' ' << j << ' ' << k << endl;
int res; cin >> res;
return res;
};
int Q(vector<int> a) {
return Q(a[0], a[1], a[2]);
};
int Q2(int i, int j) {
int res; cin >> res; res--;
return res;
}
void Solve() {
int N;
cin >> N;
Vec<1, int> ans(N);
Vec<2, int> reses(4);
int small = oo;
int big = -oo;
Vec<1, int> small_ind;
Vec<1, int> big_ind;
FOR(i, 4) {
Vec<1, int> a;
FOR(j, 4) {
if (i == j)continue;
a.push_back(j);
}
int r = Q(a);
for (int e : a) {
reses[e].push_back(r);
}
ckmin(small, r);
ckmax(big, r);
}
FOR(i, 4) {
int count = 0;
FOR(j, 3) {
if (reses[i][j] == small) {
count++;
}
}
if (count == 2) {
small_ind.push_back(i);
} else {
big_ind.push_back(i);
}
}
FOR(i, 4, N) {
int r = Q(small_ind[0], big_ind[0], i);
if (r > small && r < big) {
ans[i] = r;
continue;
}
if (r <= small) {
if (r == small) {
ans[small_ind[0]] = small;
small_ind.erase(small_ind.begin());
small_ind.push_back(i);
small = Q(small_ind[0], small_ind[1], big_ind[0]);
} else {
ans[small_ind[1]] = small;
small_ind.erase(small_ind.begin() + 1);
small_ind.push_back(i);
small = r;
}
continue;
}
if (r == big) {
ans[big_ind[0]] = big;
big_ind.erase(big_ind.begin());
big_ind.push_back(i);
big = Q(big_ind[0], big_ind[1], small_ind[0]);
} else {
ans[big_ind[1]] = big;
big_ind.erase(big_ind.begin() + 1);
big_ind.push_back(i);
big = r;
}
}
int s = Q2(small_ind[0], small_ind[1]);
ans[s] = 1;
if (s == small_ind[0]) {
ans[small_ind[1]] = 2;
} else {
ans[small_ind[0]] = 2;
}
s = Q2(big_ind[0], big_ind[1]);
ans[s] = N - 1;
if (s == big_ind[0]) {
ans[big_ind[1]] = N;
} else {
ans[big_ind[0]] = N;
}
cout << "! " << ans;
}
int main() {
Solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
5
output:
1 2 3 4