# include <bits/stdc++.h>
# include <gondola.h>
using namespace std;
long long n,idx,a[300005],b[300005],x1,x22,x2,num,x11,mx,ans[300005],cnt,anss,raod;
pair <long long , long long > x;
long long y;
map <long long, long long> mp;
multiset <pair <long long , long long > > ms;
vector <long long> v;
long long mod=1e9+9;
int valid(int n , int a[])
{
//cin>>n;
idx=-1;
for (int i=0; i<n; i++)
{
// cin>>a[i];
if (mp[a[i]]) y=1;
mp[a[i]]=1;
if (a[i]<=n) idx=i;
}
if (y==1)
{
return 0;
}
if (idx==-1)
{
return 1;
}
num=a[idx];
for (int i=idx+1; i<n; i++)
{
num++;
if (num==n+1) num=1;
if (a[i]<=n && a[i]!=num)
{
return 0;
}
}
for (int i=0; i<idx; i++)
{
num++;
if (num==n+1) num=1;
if (a[i]<=n && a[i]!=num)
{
return 0;
}
}
return 1;
}
int replacement(int n, int a[], int ans[])
{
idx=-1;
for (int i=0; i<n; i++)
{
mp[a[i]]=1;
if (a[i]<=n) idx=i;
}
if (idx==-1)
{
for (int i=0; i<n; i++)
b[i]=i+1;
for (int i=0; i<n; i++)
{
ms.insert({a[i],b[i]});
}
x2=n;
while (ms.size())
{
x=*ms.begin();
x11=x.first;
x22=x.second;
if (x11!=x22)
{
ans[cnt]=x22;
cnt++;
x2++;
}
else
{
ms.erase(ms.find({x11,x22}));
continue;
}
while (x11>x2)
{
ans[cnt]=x2;
cnt++;
x2++;
}
x2=x11;
ms.erase(ms.find({x11,x22}));
}
}
else
{
b[idx]=a[idx];
num=a[idx];
for(int i=idx+1; i<n; i++)
{
num++;
if (num==n+1) num=1;
b[i]=num;
}
for (int i=0; i<n; i++)
{
num++;
if (num==n+1) num=1;
b[i]=num;
}
for (int i=0; i<n; i++)
{
ms.insert({a[i],b[i]});
}
x2=n;
while (ms.size())
{
x=*ms.begin();
x11=x.first;
x22=x.second;
if (x11!=x22)
{
ans[cnt]=x22;
cnt++;
x2++;
}
else
{
ms.erase(ms.find({x11,x22}));
continue;
}
while (x11>x2)
{
ans[cnt]=x2;
cnt++;
x2++;
}
x2=x11;
ms.erase(ms.find({x11,x22}));
}
}
return cnt;
}
long long f_p(long long base, long long power)
{
long long result = 1;
while(power>0)
{
if(power%2==1)
{
result=(result*base)%mod;
}
base=(base*base)%mod;
power=power/2;
}
return result;
}
int countReplacement(int n, int a[])
{
idx=-1;
for (int i=0; i<n; i++)
{
if (mp[a[i]]) y=1;
mp[a[i]]=1;
if (a[i]<=n) idx=i;
}
if (y==1)
{
return 0;
}
if (idx!=-1)
{
num=a[idx];
for (int i=idx+1; i<n; i++)
{
num++;
if (num==n+1) num=1;
if (a[i]<=n && a[i]!=num)
{
return 0;
}
}
for (int i=0; i<idx; i++)
{
num++;
if (num==n+1) num=1;
if (a[i]<=n && a[i]!=num)
{
return 0;
}
}
}
for (int i=0; i<n; i++)
{
if (a[i]>n) v.push_back(a[i]);
}
sort(v.begin(), v.end());
if (v.size()==0)
{
return 1;
}
anss=1;
if (v.size()==n) anss=n;
raod=v.size();
anss*=f_p(raod, v[0]-n-1);
anss%=mod;
for (int i=1; i<v.size(); i++)
{
raod--;
anss*=f_p(raod,v[i]-v[i-1]-1);
anss%=mod;
}
return anss;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:202:17: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
202 | if (v.size()==n) anss=n;
| ~~~~~~~~^~~
gondola.cpp:206:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
206 | for (int i=1; i<v.size(); i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
18 ms |
3052 KB |
Output is correct |
7 |
Correct |
42 ms |
5092 KB |
Output is correct |
8 |
Correct |
36 ms |
5476 KB |
Output is correct |
9 |
Correct |
10 ms |
2028 KB |
Output is correct |
10 |
Correct |
41 ms |
6372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
396 KB |
Output is correct |
6 |
Correct |
17 ms |
3044 KB |
Output is correct |
7 |
Correct |
43 ms |
5220 KB |
Output is correct |
8 |
Correct |
36 ms |
5476 KB |
Output is correct |
9 |
Correct |
10 ms |
2028 KB |
Output is correct |
10 |
Correct |
41 ms |
6380 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
19 ms |
2924 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
72 ms |
6500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
360 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
57 ms |
11620 KB |
Output is correct |
12 |
Correct |
68 ms |
13156 KB |
Output is correct |
13 |
Correct |
37 ms |
5988 KB |
Output is correct |
14 |
Correct |
56 ms |
11492 KB |
Output is correct |
15 |
Correct |
33 ms |
4452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
52 ms |
6376 KB |
Output is correct |
10 |
Correct |
43 ms |
5476 KB |
Output is correct |
11 |
Correct |
15 ms |
2412 KB |
Output is correct |
12 |
Correct |
18 ms |
2672 KB |
Output is correct |
13 |
Correct |
4 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
70 ms |
6512 KB |
Output is correct |
10 |
Correct |
39 ms |
5476 KB |
Output is correct |
11 |
Correct |
19 ms |
2416 KB |
Output is correct |
12 |
Correct |
18 ms |
2800 KB |
Output is correct |
13 |
Correct |
4 ms |
876 KB |
Output is correct |
14 |
Correct |
86 ms |
7780 KB |
Output is correct |
15 |
Correct |
80 ms |
8676 KB |
Output is correct |
16 |
Correct |
12 ms |
2028 KB |
Output is correct |
17 |
Correct |
48 ms |
5856 KB |
Output is correct |
18 |
Correct |
26 ms |
3696 KB |
Output is correct |