#include "gondola.h"
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while(c<'0'||c>'9')
{
c=getchar_unlocked();
}
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+c-'0';
c=getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf=1e9;
const int mod2=1e9+9;
const int mod1=998244353;
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c,d,e;
};
int n,m,s1,s2,s4,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,dem4,l,r,mid;
int i,s10,s12;
long long s3;
int kk;
int el=29;
int a[100001];
int b[250001];
vector<int> v;
set<int> s;
int valid(int n, int inputSeq[])
{
for(int i=1; i<=n; i++)
a[i]=inputSeq[i-1];
for(int i=1; i<=n; i++)
{
if(s.find(a[i])!=s.end()) return 0;
if(a[i]<=n)
{
s2=i;
}
s.insert(a[i]);
}
if(s2==0) return 1;
for(int i=1; i<=n; i++)
{
if(a[i]<=n)
{
s3=a[s2]+i-s2;
if(s3<=0) s3+=n;
if(s3>n )s3-=n;
if(s3!=a[i])
{
///cout<<s3<<" "<<i<<" "<<s2,down
return 0;
}
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
for(int i=1; i<=n; i++)
a[i]=gondolaSeq[i-1];
for(int i=1; i<=n; i++)
if(a[i]<=n) s4=i;
for(int i=1; i<=n; i++)
{
s3=a[s4]+i-s4;
if(s3<=0) s3+=n;
if(s3>n )s3-=n;
b[a[i]]=s3,s2=max(s2,a[i]);
}
s3=n+1;
dem=-1;
for(int i=n+1; i<=s2; i++)
{
if(b[i])
{
replacementSeq[++dem]=b[i];
for(int j=s3; j<i; j++)
replacementSeq[++dem]=j;
s3=i+1;
}
}
return dem+1;
}
long long ipow(int x, int p)
{
long long ret = 1, piv = x;
while(p)
{
if(p&1) ret *= piv;
piv *= piv;
ret %= mod2;
piv %= mod2;
p >>= 1;
}
return ret;
}
int countReplacement(int n, int inputSeq[])
{
for(int i=1; i<=n; i++)
a[i]=inputSeq[i-1];
for(int i=1; i<=n; i++)
{
if(s.find(a[i])!=s.end()) return 0;
if(a[i]<=n)
{
s2=i;
}
s.insert(a[i]);
}
if(s2!=0)
{
for(int i=1; i<=n; i++)
{
if(a[i]<=n)
{
s3=a[s2]+i-s2;
if(s3<=0) s3+=n;
if(s3>n )s3-=n;
if(s3!=a[i])
{
///cout<<s3<<" "<<i<<" "<<s2,down
return 0;
}
}
}
}
for(int i=1; i<=n; i++)
{
if(a[i]>n) v.pb(a[i]);
}
sort(v.begin(),v.end());
s2=n;
s3=1;
dem=v.size();
if(dem==n)s3=n;
for(auto x:v)
{
s3=(s3*ipow(dem,x-s2-1))%mod2;
dem--;
s2=x;
}
return s3;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
10 ms |
4596 KB |
Output is correct |
7 |
Correct |
7 ms |
3340 KB |
Output is correct |
8 |
Correct |
19 ms |
6480 KB |
Output is correct |
9 |
Correct |
5 ms |
3676 KB |
Output is correct |
10 |
Correct |
23 ms |
6996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
10 ms |
4444 KB |
Output is correct |
7 |
Correct |
7 ms |
3220 KB |
Output is correct |
8 |
Correct |
22 ms |
6480 KB |
Output is correct |
9 |
Correct |
7 ms |
3644 KB |
Output is correct |
10 |
Correct |
21 ms |
7000 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2496 KB |
Output is correct |
13 |
Correct |
12 ms |
4376 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
33 ms |
7260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
6 ms |
1628 KB |
Output is correct |
12 |
Correct |
8 ms |
1896 KB |
Output is correct |
13 |
Correct |
8 ms |
1884 KB |
Output is correct |
14 |
Correct |
6 ms |
1628 KB |
Output is correct |
15 |
Correct |
22 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
448 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
38 ms |
6984 KB |
Output is correct |
10 |
Correct |
32 ms |
6248 KB |
Output is correct |
11 |
Correct |
11 ms |
3924 KB |
Output is correct |
12 |
Correct |
14 ms |
4188 KB |
Output is correct |
13 |
Correct |
3 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2496 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
31 ms |
7024 KB |
Output is correct |
10 |
Correct |
25 ms |
6224 KB |
Output is correct |
11 |
Correct |
10 ms |
3932 KB |
Output is correct |
12 |
Correct |
14 ms |
4184 KB |
Output is correct |
13 |
Correct |
3 ms |
2904 KB |
Output is correct |
14 |
Correct |
39 ms |
8064 KB |
Output is correct |
15 |
Correct |
47 ms |
8664 KB |
Output is correct |
16 |
Correct |
8 ms |
3676 KB |
Output is correct |
17 |
Correct |
31 ms |
6604 KB |
Output is correct |
18 |
Correct |
16 ms |
4952 KB |
Output is correct |