QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#792228#1813. Joy with Permutationsninjadoggy1234RE 0ms0kbC++207.7kb2024-11-29 07:43:062024-11-29 07:43:07

Judging History

你现在查看的是最新测评结果

  • [2024-11-29 07:43:07]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-29 07:43:06]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef LOCAL_RUN
#include <filesystem>
#endif
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int long long
#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<size_t N, typename T>struct Arr :public array<T, N> { Arr() = default; Arr(const T& v) :array<T, N>{} { this->fill(v); }Arr(initializer_list<T>i) :array<T, N>{} { copy(i.begin(), i.end(), this->begin()); }template<typename...A, typename = enable_if_t<N == sizeof...(A)>>Arr(A&&...a) : array<T, N>{ static_cast<T>(a)... } {}Arr& operator=(const T& v) { this->fill(v); return*this; }Arr& operator+=(const Arr& o) { FOR(i, N)(*this)[i] += o[i]; return*this; }Arr& operator-=(const Arr& o) { FOR(i, N)(*this)[i] -= o[i]; return*this; }Arr operator+(const Arr& o)const { Arr r = *this; r += o; return r; }Arr operator-(const Arr& o)const { Arr r = *this; r -= o; return r; }friend istream& operator>>(istream& in, Arr& a) { FOR(i, N)in >> a[i]; return in; }friend ostream& operator<<(ostream& out, const Arr& a) { FOR(i, N)out << a[i] << " \n"[i == N - 1]; return out; } }; namespace std { template<size_t N, typename T>struct tuple_size<Arr<N, T>> :integral_constant<size_t, N> {}; template<size_t I, size_t N, typename T>struct tuple_element<I, Arr<N, T>> { using type = T; }; template<size_t I, size_t N, typename T>T get(const Arr<N, T>& a) { return a[I]; } };
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<typename Edge> struct Graph { struct OutgoingEdges { const Graph* g; int l, r; OutgoingEdges(const Graph* g, int l, int r) : g(g), l(l), r(r) {} const Edge* begin() const { return l == r ? nullptr : &g->prepared_edges[l]; } const Edge* end() const { return l == r ? nullptr : &g->prepared_edges[r]; } }; vector<Edge> prepared_edges; vector<pair<int, Edge>> edges; vector<int> start; int N; inline int size() { return N - 1; } Graph() {} Graph(int N) :N(N + 1), start(N + 2) {} void AddEdge(int from, const Edge& e) { edges.emplace_back(from, e); } void Prepare() { for (const auto& e : edges) ++start[e.first + 1]; for (int i = 1; i < N; ++i) start[i] += start[i - 1]; prepared_edges.resize(edges.size() + 1); auto counter = start; for (const auto& e : edges) prepared_edges[counter[e.first]++] = e.second; } OutgoingEdges operator[](int from) const { return (from < 0 || from + 1 >= start.size()) ? OutgoingEdges(this, 0, 0) : OutgoingEdges(this, start[from], start[from + 1]); } };
inline Graph<int> ReadGraph(int N, int M, bool undirected = true, bool one_indexed = true) { Graph<int> adj(N); FOR(i, M) { int a, b; cin >> a >> b; if (one_indexed) { a--; b--; }adj.AddEdge(a, b); if (undirected) { adj.AddEdge(b, a); } }adj.Prepare(); return adj; }
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 string YN[2] = { "NO\n","YES\n" };
const int oo = 3e18;

struct Solution {
	const static bool kReadTestCases = 0;
	stringstream out;
	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) {
		cout << 2 << ' ' << i + 1 << ' ' << j + 1 << endl;
		int res; cin >> res; res--;
		return res;
	}

	void Solve(stringstream& out, const bool kNeedToClear = false, int test_case = 1) {
		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;
	}

	void Precompute() {

	}

	stringstream& Run() {
		Precompute();
		out << fixed << setprecision(20);
		int num_cases = 1;
		if (kReadTestCases)cin >> num_cases;
		for (int test_case = 1; test_case <= num_cases; test_case++) {
			Solve(out, test_case < num_cases, test_case);
		}
		return out;
	}

};

#ifdef LOCAL_RUN
const int kTestCase = -1;
#include "_LocalIO.h"
#include "_StressTester.h"
#endif

Solution solution;
int32_t main() {
#ifdef LOCAL_RUN
	//StressTester::Run(__FILE__);
	if (LocalIO::PerformRuns(__FILE__)) return 0;
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	auto& out = solution.Run();
	cout << out.str(); cout.flush();
	return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

5

output:

1 2 3 4

result: