#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef long long ll;
typedef pair < ll , ll > pp;
const ll mod = 1e9 + 9;
const int N = 7e4 + 4;
const int K = 288;
vector < pp > V[N];
map < ll , int > M[N];
pp T[N];
ll L[N],ans[N],n,u,i,j,k,x,y,t;
char s[N*10];
void f(ll &r, ll x) { r = (r + x + mod*3) % mod; }
int main(){
scanf("%lld",&n);
V[0].pb( mp(0,0) ); M[0][0]=1;
y = 0;
for(i=1;i<=n;i++){
scanf(" %s", s);
u = strlen(s);
x = 0;
for(j=0;j<u;j++)
x = (x*10LL + s[j]-'0') % mod;
t = (x-y-1+mod*3) % mod;
for(j=0;j<K;j++)
if(M[j][ (t - L[j] + mod) % mod ]){
for(k=0;k<V[j].size();k++)
f(V[j][k].st , L[j]);
L[j] = 0;
for(k=0;k<V[j].size();k++)
if(V[j][k].st == t){
V[j].insert(V[j].begin() + ++k , mp(t,i));
break;
}
f(t,1);
for(; k<V[j].size(); k++)
f(V[j][k].st,t);
M[j].clear();
for(auto x : V[j]) M[j][x.st] = 1;
for(j++; j<K; j++) f(L[j],t);
break;
}
y = x;
/////
if(i>>8 != i+1>>8){
t = 0;
for(j=0;j<K;j++){
for(auto x : V[j]){
T[++t] = mp(x.st+L[j],x.nd);
f(T[t].st,0);
}
V[j].clear();
M[j].clear();
L[j] = 0;
}
for(j=1;j<=t;j++){
V[j>>8].pb(T[j]);
M[j>>8][ T[j].st ] = 1;
}
}
}
for(t=i=0;i<K;i++)
for(auto x : V[i])
ans[ x.nd ] = ++t;
for(i=1;i<=n;i++)
printf("%lld ",ans[i]-1);
return 0;
}
Compilation message
permutation.cpp: In function 'int main()':
permutation.cpp:37:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(k=0;k<V[j].size();k++)
~^~~~~~~~~~~~
permutation.cpp:40:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(k=0;k<V[j].size();k++)
~^~~~~~~~~~~~
permutation.cpp:46:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; k<V[j].size(); k++)
~^~~~~~~~~~~~
permutation.cpp:56:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(i>>8 != i+1>>8){
~^~
permutation.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&n);
~~~~~^~~~~~~~~~~
permutation.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %s", s);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
Output is correct |
2 |
Correct |
16 ms |
5348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
Output is correct |
2 |
Correct |
16 ms |
5348 KB |
Output is correct |
3 |
Correct |
27 ms |
5596 KB |
Output is correct |
4 |
Correct |
17 ms |
5596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
Output is correct |
2 |
Correct |
16 ms |
5348 KB |
Output is correct |
3 |
Correct |
27 ms |
5596 KB |
Output is correct |
4 |
Correct |
17 ms |
5596 KB |
Output is correct |
5 |
Correct |
3940 ms |
11100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
Output is correct |
2 |
Correct |
16 ms |
5348 KB |
Output is correct |
3 |
Correct |
27 ms |
5596 KB |
Output is correct |
4 |
Correct |
17 ms |
5596 KB |
Output is correct |
5 |
Correct |
3940 ms |
11100 KB |
Output is correct |
6 |
Execution timed out |
4099 ms |
11100 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
Output is correct |
2 |
Correct |
16 ms |
5348 KB |
Output is correct |
3 |
Correct |
27 ms |
5596 KB |
Output is correct |
4 |
Correct |
17 ms |
5596 KB |
Output is correct |
5 |
Correct |
3940 ms |
11100 KB |
Output is correct |
6 |
Execution timed out |
4099 ms |
11100 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
Output is correct |
2 |
Correct |
16 ms |
5348 KB |
Output is correct |
3 |
Correct |
27 ms |
5596 KB |
Output is correct |
4 |
Correct |
17 ms |
5596 KB |
Output is correct |
5 |
Correct |
3940 ms |
11100 KB |
Output is correct |
6 |
Execution timed out |
4099 ms |
11100 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
Output is correct |
2 |
Correct |
16 ms |
5348 KB |
Output is correct |
3 |
Correct |
27 ms |
5596 KB |
Output is correct |
4 |
Correct |
17 ms |
5596 KB |
Output is correct |
5 |
Correct |
3940 ms |
11100 KB |
Output is correct |
6 |
Execution timed out |
4099 ms |
11100 KB |
Time limit exceeded |