#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 1000000000
#define MOD 25591308716929
#define N 70005
#define MAX 10000006
#define LOG 30
#define KOK 200
#define form(x) (x<0?x+MOD:x>=MOD?x-MOD:x)
using namespace std;
int n,gsz,cache,len;
ll prevv;
ll lazy[KOK*2+105];
int sz[KOK*2+105],ans[N];
pair<ll,int> GR[KOK*2+105][KOK*5+100];
pair<ll,int> ar[N];
char s[N*20];
unordered_set<ll> MP[KOK*2+105];
ll get_hash() {
ll res=0;
for(int i=1;i<=len;i++) res=(res*10+(s[i]-'0'))%MOD;
return res;
}
void rebuild() {
int cnt=0;
cache=0;
for(int i=1;i<=gsz;i++) {
for(int j=1;j<=sz[i];j++) {
GR[i][j].st=form(GR[i][j].st+lazy[i]);
ar[++cnt]=GR[i][j];
}
MP[i].clear();
}
gsz=0;
for(int i=1;i<=cnt;i+=KOK) {
++gsz;
sz[gsz]=0;
lazy[gsz]=0;
for(int j=i;j<=min(i+KOK-1,cnt);j++) {
GR[gsz][++sz[gsz]]=ar[j];
MP[gsz].insert(ar[j].st);
}
}
}
void insert_here(ll val,int ith,int gr) {
MP[gr].clear();
if(lazy[gr]) {
for(int i=1;i<=sz[gr];i++) GR[gr][i].st=form(GR[gr][i].st+lazy[gr]);
lazy[gr]=0;
}
for(int i=sz[gr];i>=1;i--) {
if((GR[gr][i].st+1)==val) {
GR[gr][i+1]={form(GR[gr][i].st+val),ith};
break ;
}
GR[gr][i+1]=GR[gr][i];
GR[gr][i+1].st=form(GR[gr][i+1].st+val);
}
sz[gr]++;
for(int i=1;i<=sz[gr];i++) {
MP[gr].insert(GR[gr][i].st);
}
}
void insert(ll val,int ith) {
cache++;
for(int i=gsz;i>=1;i--) {
ll want=form(val-lazy[i]-1+MOD);
if(MP[i].find(want)!=MP[i].end()) {
insert_here(val,ith,i);
if(cache==KOK*4) {
rebuild();
}
return ;
}
else lazy[i]=form(lazy[i]+val);
}
}
int main() {
//freopen("input.txt","r",stdin);
for(int i=0;i<KOK*2+105;i++) {
MP[i].reserve(512);
MP[i].max_load_factor(0.25);
}
scanf("%d",&n);
gsz=1;
GR[1][1]={0,0};
sz[1]=1;
MP[1].insert(0);
for(int i=1;i<=n;i++) {
scanf("%s",s+1);
len=strlen(s+1);
ll num=get_hash();
ll no=form(num-prevv+MOD);
prevv=num;
insert(no,i);
}
int val=-1;
for(int i=1;i<=gsz;i++) {
for(int j=1;j<=sz[i];j++) {
ans[GR[i][j].nd]=++val;
}
}
for(int i=1;i<=n;i++) printf("%d ",ans[i]);
}
Compilation message
permutation.cpp: In function 'int main()':
permutation.cpp:163:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
permutation.cpp:175:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",s+1);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2552 KB |
Output is correct |
2 |
Correct |
10 ms |
2552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2552 KB |
Output is correct |
2 |
Correct |
10 ms |
2552 KB |
Output is correct |
3 |
Correct |
22 ms |
2740 KB |
Output is correct |
4 |
Correct |
23 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2552 KB |
Output is correct |
2 |
Correct |
10 ms |
2552 KB |
Output is correct |
3 |
Correct |
22 ms |
2740 KB |
Output is correct |
4 |
Correct |
23 ms |
2816 KB |
Output is correct |
5 |
Correct |
1269 ms |
7384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2552 KB |
Output is correct |
2 |
Correct |
10 ms |
2552 KB |
Output is correct |
3 |
Correct |
22 ms |
2740 KB |
Output is correct |
4 |
Correct |
23 ms |
2816 KB |
Output is correct |
5 |
Correct |
1269 ms |
7384 KB |
Output is correct |
6 |
Correct |
3031 ms |
10980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2552 KB |
Output is correct |
2 |
Correct |
10 ms |
2552 KB |
Output is correct |
3 |
Correct |
22 ms |
2740 KB |
Output is correct |
4 |
Correct |
23 ms |
2816 KB |
Output is correct |
5 |
Correct |
1269 ms |
7384 KB |
Output is correct |
6 |
Correct |
3031 ms |
10980 KB |
Output is correct |
7 |
Correct |
2757 ms |
11040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2552 KB |
Output is correct |
2 |
Correct |
10 ms |
2552 KB |
Output is correct |
3 |
Correct |
22 ms |
2740 KB |
Output is correct |
4 |
Correct |
23 ms |
2816 KB |
Output is correct |
5 |
Correct |
1269 ms |
7384 KB |
Output is correct |
6 |
Correct |
3031 ms |
10980 KB |
Output is correct |
7 |
Correct |
2757 ms |
11040 KB |
Output is correct |
8 |
Correct |
1679 ms |
11040 KB |
Output is correct |
9 |
Correct |
3107 ms |
11424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2552 KB |
Output is correct |
2 |
Correct |
10 ms |
2552 KB |
Output is correct |
3 |
Correct |
22 ms |
2740 KB |
Output is correct |
4 |
Correct |
23 ms |
2816 KB |
Output is correct |
5 |
Correct |
1269 ms |
7384 KB |
Output is correct |
6 |
Correct |
3031 ms |
10980 KB |
Output is correct |
7 |
Correct |
2757 ms |
11040 KB |
Output is correct |
8 |
Correct |
1679 ms |
11040 KB |
Output is correct |
9 |
Correct |
3107 ms |
11424 KB |
Output is correct |
10 |
Correct |
3210 ms |
11804 KB |
Output is correct |