#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
ll sq = 100;
ll mod = 2987623948576237;
ll n;
ll a[70009];
vector<pll> v[70009];
vector<pll> val[70009];
void add(ll seg, ll idx, ll num){
if(idx == -1)
v[seg].insert(v[seg].begin()+idx+1, {a[num], num});
else
v[seg].insert(v[seg].begin()+idx+1, {(seg[v][idx].ff+a[num])%mod, num});
for(int i = idx+2; i < v[seg].size(); ++i){
v[seg][i].ff = (a[v[seg][i].ss]+v[seg][i-1].ff);
if(v[seg][i].ff >= mod)
v[seg][i].ff -= mod;
}
val[seg].clear();
for(ll i = 0; i < v[seg].size(); ++i)
val[seg].pb({v[seg][i].ff, i});
sort(all(val[seg]));
}
void restruct(){
vector<ll> tmp;
for(ll i = 0; v[i].size(); ++i){
val[i].clear();
for(auto u : v[i])
tmp.pb(u.ss);
v[i].clear();
}
//return;
for(ll i = 0; i < tmp.size(); ++i){
if(v[i/sq].size() == 0)
v[i/sq].pb({a[tmp[i]], tmp[i]});
else
v[i/sq].pb({(a[tmp[i]]+v[i/sq].back().ff)%mod, tmp[i]});
val[i/sq].pb({v[i/sq].back().ff, v[i/sq].size()-1});
if(i == tmp.size()-1 || i%sq == sq-1)
sort(all(val[i/sq]));
}
//exit(0);
}
ll ans[70009];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n;
for(ll i = 1; i <= n; ++i){
string s;
cin >> s;
for(auto u : s){
a[i] = a[i]*10%mod;
a[i] += u-'0';
if(a[i] >= mod)
a[i]-=mod;
}
}
for(ll i = n; i >= 1; --i){
a[i] = a[i]-a[i-1]+mod;
if(a[i] >= mod)
a[i] -= mod;
}
for(ll i = 1; i <= n; ++i){
if(i%sq == 0)
restruct();
if(a[i] == 1){
add(0, -1, i);
continue;
}
ll lookfor = a[i]-1;
for(ll j = 0;; ++j){
ll k = lower_bound(all(val[j]), mp(lookfor, 0LL))-val[j].begin();
if(k != val[j].size() && val[j][k].ff == lookfor){
add(j, k, i);
break;
}
lookfor = lookfor-v[j].back().ff+mod;
if(lookfor >= mod)
lookfor -= mod;
if(v[j].empty()) break;
}
}
ll cur = 1;
for(ll i = 0; v[i].size(); ++i)
for(auto u : v[i])
ans[u.ss] = cur++;
for(ll i = 1; i <= n; ++i)
cout << ans[i] << ' ';
}
Compilation message
permutation.cpp: In function 'void add(ll, ll, ll)':
permutation.cpp:26:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = idx+2; i < v[seg].size(); ++i){
| ~~^~~~~~~~~~~~~~~
permutation.cpp:32:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(ll i = 0; i < v[seg].size(); ++i)
| ~~^~~~~~~~~~~~~~~
permutation.cpp: In function 'void restruct()':
permutation.cpp:45:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(ll i = 0; i < tmp.size(); ++i){
| ~~^~~~~~~~~~~~
permutation.cpp:51:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | if(i == tmp.size()-1 || i%sq == sq-1)
| ~~^~~~~~~~~~~~~~~
permutation.cpp: In function 'int main()':
permutation.cpp:90:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | if(k != val[j].size() && val[j][k].ff == lookfor){
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3584 KB |
Output is correct |
2 |
Correct |
4 ms |
3712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3584 KB |
Output is correct |
2 |
Correct |
4 ms |
3712 KB |
Output is correct |
3 |
Runtime error |
12 ms |
7168 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3584 KB |
Output is correct |
2 |
Correct |
4 ms |
3712 KB |
Output is correct |
3 |
Runtime error |
12 ms |
7168 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3584 KB |
Output is correct |
2 |
Correct |
4 ms |
3712 KB |
Output is correct |
3 |
Runtime error |
12 ms |
7168 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3584 KB |
Output is correct |
2 |
Correct |
4 ms |
3712 KB |
Output is correct |
3 |
Runtime error |
12 ms |
7168 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3584 KB |
Output is correct |
2 |
Correct |
4 ms |
3712 KB |
Output is correct |
3 |
Runtime error |
12 ms |
7168 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3584 KB |
Output is correct |
2 |
Correct |
4 ms |
3712 KB |
Output is correct |
3 |
Runtime error |
12 ms |
7168 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |