#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) cerr << *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 -1;
}
void modify(int st, int val) {
int id = ceil(st, sz);
rep(i, (id - 1) * sz + 1, 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;
if(cur == -1) while(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
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) cerr << *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) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Runtime error |
606 ms |
2580 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Runtime error |
606 ms |
2580 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Runtime error |
606 ms |
2580 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Runtime error |
606 ms |
2580 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Runtime error |
606 ms |
2580 KB |
Execution killed with signal 6 |