Submission #62866234
Source Code Expand
// 期待外れでいたいだなんて
// いつから願ってしまった?
// 名も知れぬほうがいいなんて
// いつからか願ってしまった
// ココロもネジ巻出して
// 意味を失ってしまった
// 何ひとつも動かせない今日と
// 押しつぶすように広がる
// 澄んだ機械仕掛けの空
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// Pragmas
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// Namespaces
using namespace std;
using namespace __gnu_pbds;
// Data types
using si = short int;
using ll = long long;
using ull = unsigned long long;
using lll = __int128;
using ld = long double;
// Pairs
using pii = pair<int, int>;
using psi = pair<si, si>;
using pll = pair<ll, ll>;
using plll = pair<lll, lll>;
using pld = pair<ld, ld>;
#define fi first
#define se second
// PBDS
template<typename Z>
using ordered_set = tree<Z, null_type, less<Z>, rb_tree_tag, tree_order_statistics_node_update>;
// Various outputs and debug
template<typename Z, typename = void> struct is_iterable : false_type {};
template<typename Z> struct is_iterable<Z, void_t<decltype(begin(declval<Z>())),decltype(end(declval<Z>()))>> : true_type {};
template<typename Z> typename enable_if<is_iterable<Z>::value&&!is_same<Z, string>::value,ostream&>::type operator<<(ostream &os, const Z &v);
template<typename Y, typename Z> ostream& operator<<(ostream &os, const pair<Y, Z> &p) {
return os << "(" << p.fi << ", " << p.se << ")";
}
template<class TupType, size_t... I> void printTuple(ostream& os, const TupType& _tup, index_sequence<I...>) {
os << "(";
(..., (os << (I == 0? "" : ", ") << get<I>(_tup)));
os << ")";
}
template<class... Z> ostream& operator<<(ostream& os, const tuple<Z...>& _tup) {
printTuple(os, _tup, make_index_sequence<sizeof...(Z)>());
return os;
}
template<typename Z> typename enable_if<is_iterable<Z>::value&&!is_same<Z, string>::value,ostream&>::type operator<<(ostream &os, const Z &v) {
os << "[";
for (auto it = v.begin(); it != v.end();) { os << *it; if (++it != v.end()) os << ", "; }
return os << "]";
}
#define debug(...) logger(cout, #__VA_ARGS__, __VA_ARGS__)
#define debugV(v, x) vlogger(cout, #v, x, v[x]);
#define rrebug(...) logger(cerr, #__VA_ARGS__, __VA_ARGS__)
#define rrebugV(v, x) vlogger(cerr, #v, x, v[x]);
template <typename... Args>
void logger(ostream& os, string vars, Args &&...values) {
os << vars << " = "; string delim = "";
(..., (os << delim << values, delim = ", "));
os << "\n";
}
template<class Y, class Z>
void vlogger(ostream& os, string var, Y idx, Z val) {
os << var << "[" << idx << "] = " << val << "\n";
}
// Various macros
#define All(x) x.begin(), x.end()
#define Sort(x) sort(All(x))
#define Reverse(x) reverse(All(x))
#define Uniqueify(x) Sort(x); x.erase(unique(All(x)), x.end())
#define RandomSeed chrono::steady_clock::now().time_since_epoch().count()
#define MultipleTestcases int _tc; cin >> _tc; for (int _cur_tc = 1; _cur_tc <= _tc; _cur_tc++)
// Chmin & chmax
template<typename Z> bool chmin(Z &a, Z b) { return (b < a) ? a = b, true : false; }
template<typename Z> bool chmax(Z &a, Z b) { return (b > a) ? a = b, true : false; }
// Modular arithmetic
template<int MOD>
class ModInt {
public:
int v;
ModInt() : v(0) {}
ModInt(long long _v) {
v = int((-MOD < _v && _v < MOD) ? (_v) : (_v % MOD));
if (v < 0) v += MOD;
}
friend bool operator==(const ModInt &a, const ModInt &b) { return a.v == b.v; }
friend bool operator!=(const ModInt &a, const ModInt &b) { return a.v != b.v; }
friend bool operator< (const ModInt &a, const ModInt &b) { return a.v < b.v; }
friend bool operator<=(const ModInt &a, const ModInt &b) { return a.v <= b.v; }
friend bool operator> (const ModInt &a, const ModInt &b) { return a.v > b.v; }
friend bool operator>=(const ModInt &a, const ModInt &b) { return a.v >= b.v; }
ModInt &operator+=(const ModInt &a) { v = (long long)(v + a.v) % MOD; return *this; }
ModInt &operator-=(const ModInt &a) { v = (long long)(v - a.v + MOD) % MOD; return *this; }
ModInt &operator*=(const ModInt &a) { v = 1ll * v * a.v % MOD; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this) *= inverse(a); }
friend ModInt pow(ModInt a, long long x) {
ModInt res = 1;
for (; x; x /= 2, a *= a) if (x & 1) res *= a;
return res;
}
friend ModInt inverse(ModInt a) { return pow(a, MOD - 2); }
ModInt operator+ () const { return ModInt( v); }
ModInt operator- () const { return ModInt(-v); }
ModInt operator++() const { return *this += 1; }
ModInt operator--() const { return *this -= 1; }
friend ModInt operator+(ModInt a, const ModInt &b) { return a += b; }
friend ModInt operator-(ModInt a, const ModInt &b) { return a -= b; }
friend ModInt operator*(ModInt a, const ModInt &b) { return a *= b; }
friend ModInt operator/(ModInt a, const ModInt &b) { return a /= b; }
friend istream &operator>>(istream &is, ModInt &v) { return is >> v.v; }
friend ostream &operator<<(ostream &os, const ModInt &v) { return os << v.v; }
};
const int ModA = 998244353;
const int ModC = 1e9 + 7;
using MintA = ModInt<ModA>;
using MintC = ModInt<ModC>;
// Other constants
const ll INF = 1e18;
const ll iINF = 1e9;
const ld EPS = 1e-9;
const ld iEPS = 1e-6;
const bool local = false;
int hp[2023];
ll ha[2023], ha_pf[2023];
mt19937_64 rng(RandomSeed);
ll query(int s, int t) {
assert(s != t);
if (local) {
int ps = hp[s], pt = hp[t];
if (ps < pt) swap(ps, pt);
return ha_pf[ps] - ha_pf[pt - 1];
}
cout << "? " << s << " " << t << endl;
ll ret; cin >> ret; return ret;
}
using Stat = tuple<int, ll, ll>;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int N;
cin >> N;
if (local) {
for (int i = 1; i <= N; i++) cin >> hp[i];
for (int i = 1; i <= N; i++) cin >> ha[i];
// for (int i = 1; i <= N; i++) {
// ha[i] = 1 + (rng() % (ll)1e9);
// }
for (int i = 1; i <= N; i++) ha_pf[i] = ha_pf[i-1] + ha[i];
}
ll d12 = query(1, 2);
array<vector<Stat>, 3> group = {};
for (int i = 3; i <= N; i++) {
ll d1i = query(1, i);
ll d2i = query(2, i);
Stat cur = {i, d1i, d2i};
if (d1i <= d12 && d2i <= d12) {
group[1].push_back(cur);
} else if (d1i <= d2i) {
group[0].push_back(cur);
} else {
group[2].push_back(cur);
}
}
sort(All(group[0]), [&](Stat a, Stat b) { return get<1>(a) > get<1>(b); });
sort(All(group[1]), [&](Stat a, Stat b) { return get<1>(a) < get<1>(b); });
sort(All(group[2]), [&](Stat a, Stat b) { return get<2>(a) < get<2>(b); });
// debug(group[0]);
// debug(group[1]);
// debug(group[2]);
vector<int> P(N + 1), pos(N + 1);
vector<ll> A(N + 1);
int t = 0;
for (auto [i, _, __] : group[0]) P[i] = ++t;
P[1] = ++t;
for (auto [i, _, __] : group[1]) P[i] = ++t;
P[2] = ++t;
for (auto [i, _, __] : group[2]) P[i] = ++t;
for (int i = 1; i <= N; i++) pos[P[i]] = i;
ll middle_sum = 0;
for (auto [i, d1i, d2i] : group[1]) {
A[P[i]] = d1i + d2i - d12;
middle_sum += A[P[i]];
}
// debug(middle_sum);
if (P[1] < N-1) {
ll q1 = query(pos[P[1]], pos[N]);
ll q2 = query(pos[P[1] + 1], pos[N]);
A[P[1]] = q1 - q2;
A[P[2]] = d12 - middle_sum - A[P[1]];
} else {
ll q1 = query(pos[1], pos[P[2]]);
ll q2 = query(pos[1], pos[P[2] - 1]);
A[P[2]] = q1 - q2;
A[P[1]] = d12 - middle_sum - A[P[2]];
}
middle_sum += A[P[1]] + A[P[2]];
if (!group[0].empty()) {
ll run = middle_sum;
for (int j = group[0].size() - 1; j >= 0; j--) {
auto [i, d1i, d2i] = group[0][j];
A[P[i]] = d2i - run;
run = d2i;
}
}
if (!group[2].empty()) {
ll run = middle_sum;
for (auto [i, d1i, d2i] : group[2]) {
A[P[i]] = d1i - run;
run = d1i;
}
}
cout << "!";
for (int i = 1; i <= N; i++) cout << " " << P[i];
for (int i = 1; i <= N; i++) cout << " " << A[i];
cout << endl;
}
// dibisakan
Submission Info
Submission Time |
|
Task |
C - Range Sums 2 |
User |
Zanite |
Language |
C++ 20 (gcc 12.2) |
Score |
600 |
Code Size |
8839 Byte |
Status |
AC |
Exec Time |
47 ms |
Memory |
4088 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
600 / 600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00-sample-001.txt |
All |
00-sample-001.txt, 01-random-001.txt, 01-random-002.txt, 01-random-003.txt, 01-random-004.txt, 01-random-005.txt, 01-random-006.txt, 01-random-007.txt, 01-random-008.txt, 01-random-009.txt, 01-random-010.txt, 01-random-011.txt, 01-random-012.txt, 01-random-013.txt, 01-random-014.txt, 01-random-015.txt, 02-large-001.txt, 02-large-002.txt, 02-large-003.txt, 02-large-004.txt, 02-large-005.txt, 02-large-006.txt, 02-large-007.txt, 02-large-008.txt, 02-large-009.txt, 02-large-010.txt, 03-small-001.txt, 03-small-002.txt, 03-small-003.txt, 03-small-004.txt, 03-small-005.txt, 03-small-006.txt, 03-small-007.txt, 03-small-008.txt, 03-small-009.txt, 03-small-010.txt, 03-small-011.txt, 03-small-012.txt, 03-small-013.txt, 03-small-014.txt, 03-small-015.txt |
Case Name |
Status |
Exec Time |
Memory |
00-sample-001.txt |
AC |
3 ms |
3684 KiB |
01-random-001.txt |
AC |
36 ms |
3816 KiB |
01-random-002.txt |
AC |
4 ms |
3684 KiB |
01-random-003.txt |
AC |
9 ms |
3664 KiB |
01-random-004.txt |
AC |
3 ms |
3676 KiB |
01-random-005.txt |
AC |
24 ms |
3824 KiB |
01-random-006.txt |
AC |
17 ms |
3680 KiB |
01-random-007.txt |
AC |
6 ms |
3772 KiB |
01-random-008.txt |
AC |
42 ms |
3976 KiB |
01-random-009.txt |
AC |
25 ms |
3832 KiB |
01-random-010.txt |
AC |
32 ms |
3888 KiB |
01-random-011.txt |
AC |
15 ms |
3664 KiB |
01-random-012.txt |
AC |
10 ms |
3648 KiB |
01-random-013.txt |
AC |
18 ms |
3720 KiB |
01-random-014.txt |
AC |
23 ms |
3888 KiB |
01-random-015.txt |
AC |
27 ms |
3724 KiB |
02-large-001.txt |
AC |
46 ms |
3956 KiB |
02-large-002.txt |
AC |
45 ms |
3864 KiB |
02-large-003.txt |
AC |
47 ms |
3980 KiB |
02-large-004.txt |
AC |
45 ms |
3832 KiB |
02-large-005.txt |
AC |
45 ms |
4004 KiB |
02-large-006.txt |
AC |
46 ms |
3984 KiB |
02-large-007.txt |
AC |
45 ms |
3932 KiB |
02-large-008.txt |
AC |
46 ms |
3920 KiB |
02-large-009.txt |
AC |
45 ms |
3980 KiB |
02-large-010.txt |
AC |
45 ms |
4088 KiB |
03-small-001.txt |
AC |
3 ms |
3664 KiB |
03-small-002.txt |
AC |
2 ms |
3592 KiB |
03-small-003.txt |
AC |
2 ms |
3732 KiB |
03-small-004.txt |
AC |
2 ms |
3532 KiB |
03-small-005.txt |
AC |
2 ms |
3548 KiB |
03-small-006.txt |
AC |
2 ms |
3664 KiB |
03-small-007.txt |
AC |
2 ms |
3604 KiB |
03-small-008.txt |
AC |
3 ms |
3564 KiB |
03-small-009.txt |
AC |
3 ms |
3544 KiB |
03-small-010.txt |
AC |
2 ms |
3600 KiB |
03-small-011.txt |
AC |
2 ms |
3608 KiB |
03-small-012.txt |
AC |
3 ms |
3600 KiB |
03-small-013.txt |
AC |
3 ms |
3728 KiB |
03-small-014.txt |
AC |
3 ms |
3752 KiB |
03-small-015.txt |
AC |
3 ms |
3680 KiB |