This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define INF 1000000000000000000
#define eps (1e-9)
using namespace std;
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cout << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
random;
int n, sz, bk;
int MOD = 1125899839733759;
vector<int> a, tag, vis, ans;
vector<pii> b;
void init_(int _n) {
n = _n, sz = sqrt(n) + 1, bk = ceil(n, sz);
a.assign(n + 1, 0);
tag.assign(bk + 1, 0);
vis.assign(n + 1, 0);
ans.assign(n + 1, 0);
b.assign(n + 1, {0, 0});
}
void build(int id) {
int l = (id - 1) * sz + 1, r = min(n, id * sz);
rep(i, l, r) {
pii cur = b[i];
if(vis[cur.second]) b[i] = {-1, cur.second};
else b[i] = {(cur.first + tag[id] + MOD) % MOD, cur.second};
}
tag[id] = 0;
sort(b.begin() + l, b.begin() + r + 1);
return;
}
int get_int(string s) {
int ans = 0;
for(auto i : s) ans = (ans * 10 + i - '0') % MOD;
return ans;
}
int query() {
rrep(i, 1, bk) {
int l = (i - 1) * sz + 1, r = min(n, i * sz);
int val = (1 - tag[i] + MOD) % MOD;
int id = upper_bound(b.begin() + l, b.begin() + r + 1, pii(val, INF)) - b.begin() - 1;
if(id <= r && id >= l && b[id].first == val) return b[id].second;
}
return 0;
}
void modify(int st, int val) {
int id = ceil(st, sz);
rep(i, (id - 1) * sz + 1, min(n, id * sz)) {
if(b[i].second >= st) b[i].first = (val + b[i].first) % MOD;
}
build(id);
rep(i, ceil(st, sz) + 1, bk) tag[i] = (tag[i] + val) % MOD;
}
void solve() {
rrep(i, 1, n) {
a[i] = (a[i] - a[i - 1] + MOD) % MOD;
b[i] = {a[i], i};
}
rep(i, 1, bk) build(i);
rep(i, 1, n) {
int cur = query();
ans[cur] = i, vis[cur] = 1;
modify(cur, MOD - a[cur]);
}
rep(i, 1, n) cout << ans[i] << " \n"[i == n];
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int n; cin >> n;
init_(n);
rep(i, 1, n) {
string s; cin >> s;
a[i] = get_int(s);
}
solve();
return 0;
}
Compilation message (stderr)
permutation.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
permutation.cpp:23:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
23 | void vprint(auto L, auto R) { while(L < R) cout << *L << " \n"[next(L) == R], ++L;}
| ^~~~
permutation.cpp:23:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
23 | void vprint(auto L, auto R) { while(L < R) cout << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |