#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010, BD = 1e9, WID = 9;
struct mint {
vector<ll> val;
mint(string s = "0") {
int len = 0, v = 0, sc = 1;
reverse(AI(s));
for (int i = 0;i < s.size();++i) {
v += sc * (s[i] - '0');
if (++len == WID) {
val.pb(v);
v = len = 0, sc = 1;
}
if (len) sc *= 10;
}
val.pb(v);
}
mint(vector<ll> v) : val(v) { upd(); }
mint(ll v) { val = {v}; upd(); }
void shrink() { while (val.size() > 1 && val.back() == 0) val.pop_back(); }
void upd() {
for (int i = 0;i < val.size();++i) {
if (val[i] >= BD) {
if (i+1 == val.size()) val.pb(0);
val[i+1] += val[i] / BD;
val[i] %= BD;
}
while (val[i] < 0) {
--val[i+1];
val[i] += BD;
}
}
}
bool operator < (mint b) {
auto &A = val, &B = b.val;
if (A.size() != B.size())
return A.size() < B.size();
for (int i = A.size() - 1;i >= 0;--i)
if (A[i] != B[i])
return A[i] < B[i];
return false;
}
bool operator > (mint b) {
return b < *this;
}
bool operator == (mint b) {
return !(*this < b) && (!(b < *this));
}
friend ostream& operator << (ostream& out, mint a) {
auto &val = a.val;
for (int i = (int)val.size()-1;i >= 0;--i)
out << setw(9) << setfill('0') << val[i];
return out;
}
};
mint operator - (mint a, mint b) {
auto A = a.val, B = b.val;
int sz = max(A.size(), B.size());
A.resize(sz), B.resize(sz);
for (int i = 0;i < A.size();++i)
A[i] -= B[i];
return mint(A);
}
mint& operator -= (mint &a, mint b) { return a = a - b; }
mint operator + (mint a, mint b) {
auto A = a.val, B = b.val;
int sz = max(A.size(), B.size());
A.resize(sz), B.resize(sz);
for (int i = 0;i < A.size();++i)
A[i] += B[i];
return mint(A);
}
mint& operator += (mint &a, mint b) { return a = a + b; }
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
vector<pair<int, mint>> per;
vector<mint> val(n);
for (mint &a : val) {
string v;
cin >> v;
a = mint(v);
}
for (int i = n-1;i > 0;--i) {
val[i] -= val[i-1];
}
for (int i = 0;i < n;++i) {
DE(i, val[i]);
for (auto [id, val] : per) {
DE(id, val);
}
mint sum = 1;
int ind = -1;
for (int j = 0;j < i;++j) {
sum += per[j].second;
ind = j;
if (sum == val[i]) {
break;
}
assert(sum < val[i]);
}
DE(i, ind, sum);
per.insert(begin(per) + ind + 1, make_pair(i, val[i]));
}
vector<int> ans(n);
for (int i = 0;i < n;++i) {
auto [id, val] = per[i];
ans[id] = i+1;
}
for (int i = 0;i < n;++i)
cout << ans[i] << " \n"[i+1==n];
}
Compilation message
permutation.cpp: In constructor 'mint::mint(std::string)':
permutation.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0;i < s.size();++i) {
| ~~^~~~~~~~~~
permutation.cpp: In member function 'void mint::upd()':
permutation.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int i = 0;i < val.size();++i) {
| ~~^~~~~~~~~~~~
permutation.cpp:41:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if (i+1 == val.size()) val.pb(0);
| ~~~~^~~~~~~~~~~~~
permutation.cpp: In function 'mint operator-(mint, mint)':
permutation.cpp:77:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for (int i = 0;i < A.size();++i)
| ~~^~~~~~~~~~
permutation.cpp: In function 'mint operator+(mint, mint)':
permutation.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int i = 0;i < A.size();++i)
| ~~^~~~~~~~~~
permutation.cpp: In function 'int32_t main()':
permutation.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
permutation.cpp:113:3: note: in expansion of macro 'DE'
113 | DE(i, val[i]);
| ^~
permutation.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
permutation.cpp:115:4: note: in expansion of macro 'DE'
115 | DE(id, val);
| ^~
permutation.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
permutation.cpp:127:3: note: in expansion of macro 'DE'
127 | DE(i, ind, sum);
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |