/*写在前面*/
/*这次算是第一次补题了,原因是在做的过程中做出了c题,可是后来重判的时候超时了,然后修修补补,终于弄好了,记录一下*/
A. Greatest Convex
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an integer kk. Find the largest integer xx, where 1≤x<k1≤x<k, such that x!+(x−1)!†x!+(x−1)!† is a multiple of ‡‡ kk, or determine that no such xx exists.
†† y!y! denotes the factorial of yy, which is defined recursively as y!=y⋅(y−1)!y!=y⋅(y−1)! for y≥1y≥1 with the base case of 0!=10!=1. For example, 5!=5⋅4⋅3⋅2⋅1⋅0!=1205!=5⋅4⋅3⋅2⋅1⋅0!=120.
‡‡ If aa and bb are integers, then aa is a multiple of bb if there exists an integer cc such that a=b⋅ca=b⋅c. For example, 1010 is a multiple of 55 but 99 is not a multiple of 66.
Input
The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. The description of test cases follows.
The only line of each test case contains a single integer kk (2≤k≤1092≤k≤109).
Output
For each test case output a single integer — the largest possible integer xx that satisfies the conditions above.
If no such xx exists, output −1−1.
Example
input
Copy
436810
output
Copy
2
5
7
9
Note
In the first test case, 2!+1!=2+1=32!+1!=2+1=3, which is a multiple of 33.
In the third test case, 7!+6!=5040+720=57607!+6!=5040+720=5760, which is a multiple of 88.
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fer(i,a,b) for(int i = a ; i <= b ; ++ i)
#define der(i,a,b) for(int i = a ; i >= b ; -- i)
#define cf int _; cin>> _; while(_--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pll pair<int,int>
#define lb lower_bound
#define ub upper_bound
#define rs u << 1 | 1
#define ls u << 1
#define pb push_back
#define y second
#define x first
#define int long long
using namespace std;
inline void mo(int &a , int b) {a = (a % b + b) % b ;}
inline int gcd(int a,int b){return b ? gcd(b , a % b) : a ;}
inline void fadd(int &x , int y , int mod) {x += y ; if(x >= mod) {x -= mod ;}}
inline void de(vector<int> v){for(auto i : v){cout << i << " ";} ; cout << '\n';} ;
inline int qpow(int a,int b,int c){int res=1%c;a%=c;while(b>0){if(b&1)res=res*a%c;a=a*a%c;b>>=1;}return res;}
inline int qadd(int a,int b,int c){int res=0;a%=c;while(b>0){if(b&1)res=(res+a)%c;a=(a+a)%c;b>>=1;}return res;}
inline char nc() { static char buf[1000000], * p1 = buf, * p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; }
inline void in(int &sum) { char ch = nc(); sum = 0; while (!(ch >= '0' && ch <= '9')) ch = nc(); while (ch >= '0' && ch <= '9') sum = (sum << 3ll) + (sum << 1ll) + (ch - 48ll), ch = nc(); }
const int N = 1e7 + 10 , M = 3010 , mod1 = 1e9 + 7 , modp = 1333331 , mod9 = 998244353 ;
const double eps = 1e-7 , pi = acos(-1.0) ;
typedef unsigned long long ll ;
int get(int a , int b)
{
return (a + b - 1) / b ;
}
int p[N] , st[N] , cnt ;
void init(int n)
{
for(int i = 2 ; i <= n ;i ++)
{
if(!st[i]) p[cnt++] = i ;
for(int j = 0 ; p[j] <= n / i ; j ++)
{
st[p[j] * i] = p[j] ;
if(i % p[j] == 0) break;
}
}
}
vector<int> v ;
void get(int x)
{
while(x > 1)
{
int j = st[x] , cc = 0 ;
if(!j)
{
if(x > 1)
{
v.pb(x) ;
}
break ;
}
while(x % j == 0)
{
x /= j ;
cc ++ ;
}
v.pb(j) ;
}
}
bool mysort(int b,int c)
{
return b>c;
}
signed main(){
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
cout<<n-1<<endl;
}
return 0;
}
/*
*
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
B. Quick Sort
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a permutation†† pp of length nn and a positive integer k≤nk≤n.
In one operation, you:
Choose kk distinct elements pi1,pi2,…,pikpi1,pi2,…,pik.
Remove them and then add them sorted in increasing order to the end of the permutation.
For example, if p=[2,5,1,3,4]p=[2,5,1,3,4] and k=2k=2 and you choose 55 and 33 as the elements for the operation, then [2,5,1,3,4]→[2,1,4,3,5][2,5,1,3,4]→[2,1,4,3,5].
Find the minimum number of operations needed to sort the permutation in increasing order. It can be proven that it is always possible to do so.
†† A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).
Input
The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers nn and kk (2≤n≤1052≤n≤105, 1≤k≤n1≤k≤n).
The second line of each test case contains nn integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n). It is guaranteed that pp is a permutation.
It is guaranteed that the sum of nn over all test cases does not exceed 105105.
Output
For each test case output a single integer — the minimum number of operations needed to sort the permutation. It can be proven that it is always possible to do so.
Example
input
Copy
43 21 2 33 13 1 24 21 3 2 44 22 3 1 4
output
Copy
0
1
1
2
Note
In the first test case, the permutation is already sorted.
In the second test case, you can choose element 33, and the permutation will become sorted as follows: [3,1,2]→[1,2,3][3,1,2]→[1,2,3].
In the third test case, you can choose elements 33 and 44, and the permutation will become sorted as follows: [1,3,2,4]→[1,2,3,4][1,3,2,4]→[1,2,3,4].
In the fourth test case, it can be shown that it is impossible to sort the permutation in 11 operation. However, if you choose elements 22 and 11 in the first operation, and choose elements 33 and 44 in the second operation, the permutation will become sorted as follows: [2,3,1,4]→[3,4,1,2]→[1,2,3,4][2,3,1,4]→[3,4,1,2]→[1,2,3,4].
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fer(i,a,b) for(int i = a ; i <= b ; ++ i)
#define der(i,a,b) for(int i = a ; i >= b ; -- i)
#define cf int _; cin>> _; while(_--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pll pair<int,int>
#define lb lower_bound
#define ub upper_bound
#define rs u << 1 | 1
#define ls u << 1
#define pb push_back
#define y second
#define x first
#define int long long
using namespace std;
inline void mo(int &a , int b) {a = (a % b + b) % b ;}
inline int gcd(int a,int b){return b ? gcd(b , a % b) : a ;}
inline void fadd(int &x , int y , int mod) {x += y ; if(x >= mod) {x -= mod ;}}
inline void de(vector<int> v){for(auto i : v){cout << i << " ";} ; cout << '\n';} ;
inline int qpow(int a,int b,int c){int res=1%c;a%=c;while(b>0){if(b&1)res=res*a%c;a=a*a%c;b>>=1;}return res;}
inline int qadd(int a,int b,int c){int res=0;a%=c;while(b>0){if(b&1)res=(res+a)%c;a=(a+a)%c;b>>=1;}return res;}
inline char nc() { static char buf[1000000], * p1 = buf, * p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; }
inline void in(int &sum) { char ch = nc(); sum = 0; while (!(ch >= '0' && ch <= '9')) ch = nc(); while (ch >= '0' && ch <= '9') sum = (sum << 3ll) + (sum << 1ll) + (ch - 48ll), ch = nc(); }
const int N = 1e7 + 10 , M = 3010 , mod1 = 1e9 + 7 , modp = 1333331 , mod9 = 998244353 ;
const double eps = 1e-7 , pi = acos(-1.0) ;
typedef unsigned long long ll ;
int get(int a , int b)
{
return (a + b - 1) / b ;
}
int p[N] , st[N] , cnt ;
void init(int n)
{
for(int i = 2 ; i <= n ;i ++)
{
if(!st[i]) p[cnt++] = i ;
for(int j = 0 ; p[j] <= n / i ; j ++)
{
st[p[j] * i] = p[j] ;
if(i % p[j] == 0) break;
}
}
}
vector<int> v ;
void get(int x)
{
while(x > 1)
{
int j = st[x] , cc = 0 ;
if(!j)
{
if(x > 1)
{
v.pb(x) ;
}
break ;
}
while(x % j == 0)
{
x /= j ;
cc ++ ;
}
v.pb(j) ;
}
}
bool mysort(int b,int c)
{
return b>c;
}
int a[100005];
signed main(){
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
int flag=1;
for(int i=0;i<n;i++)
{
if(a[i]==flag)
flag++;
}
flag--;
cout<<ceil((n-flag)*1.0/k)<<endl;
}
return 0;
}
/*
*
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
C. Elemental Decompress
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an array aa of nn integers.
Find two permutations†† pp and qq of length nn such that max(pi,qi)=aimax(pi,qi)=ai for all 1≤i≤n1≤i≤n or report that such pp and qq do not exist.
†† A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).
Input
The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105).
The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n) — the array aa.
It is guaranteed that the total sum of nn over all test cases does not exceed 2⋅1052⋅105.
Output
For each test case, if there do not exist pp and qq that satisfy the conditions, output "NO" (without quotes).
Otherwise, output "YES" (without quotes) and then output 22 lines. The first line should contain nn integers p1,p2,…,pnp1,p2,…,pn and the second line should contain nn integers q1,q2,…,qnq1,q2,…,qn.
If there are multiple solutions, you may output any of them.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
Example
input
Copy
31155 3 4 2 521 1
output
Copy
YES
1
1
YES
1 3 4 2 5
5 2 3 1 4
NO
Note
In the first test case, p=q=[1]p=q=[1]. It is correct since a1=max(p1,q1)=1a1=max(p1,q1)=1.
In the second test case, p=[1,3,4,2,5]p=[1,3,4,2,5] and q=[5,2,3,1,4]q=[5,2,3,1,4]. It is correct since:
a1=max(p1,q1)=max(1,5)=5a1=max(p1,q1)=max(1,5)=5,
a2=max(p2,q2)=max(3,2)=3a2=max(p2,q2)=max(3,2)=3,
a3=max(p3,q3)=max(4,3)=4a3=max(p3,q3)=max(4,3)=4,
a4=max(p4,q4)=max(2,1)=2a4=max(p4,q4)=max(2,1)=2,
a5=max(p5,q5)=max(5,4)=5a5=max(p5,q5)=max(5,4)=5.
In the third test case, one can show that no such pp and qq exist.
/***************************解释************************/
这里我用了很多个数组(还好元素值不是很大),用来储存各种各样的数据,因为使用下标访问会很快
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fer(i,a,b) for(int i = a ; i <= b ; ++ i)
#define der(i,a,b) for(int i = a ; i >= b ; -- i)
#define cf int _; cin>> _; while(_--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pll pair<int,int>
#define lb lower_bound
#define ub upper_bound
#define rs u << 1 | 1
#define ls u << 1
#define pb push_back
#define y second
#define x first
#define int long long
using namespace std;
inline void mo(int &a , int b) {a = (a % b + b) % b ;}
inline int gcd(int a,int b){return b ? gcd(b , a % b) : a ;}
inline void fadd(int &x , int y , int mod) {x += y ; if(x >= mod) {x -= mod ;}}
inline void de(vector<int> v){for(auto i : v){cout << i << " ";} ; cout << '\n';} ;
inline int qpow(int a,int b,int c){int res=1%c;a%=c;while(b>0){if(b&1)res=res*a%c;a=a*a%c;b>>=1;}return res;}
inline int qadd(int a,int b,int c){int res=0;a%=c;while(b>0){if(b&1)res=(res+a)%c;a=(a+a)%c;b>>=1;}return res;}
inline char nc() { static char buf[1000000], * p1 = buf, * p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; }
inline void in(int &sum) { char ch = nc(); sum = 0; while (!(ch >= '0' && ch <= '9')) ch = nc(); while (ch >= '0' && ch <= '9') sum = (sum << 3ll) + (sum << 1ll) + (ch - 48ll), ch = nc(); }
const int N = 1e7 + 10 , M = 3010 , mod1 = 1e9 + 7 , modp = 1333331 , mod9 = 998244353 ;
const double eps = 1e-7 , pi = acos(-1.0) ;
typedef unsigned long long ll ;
int a[200005];
int b[200005];
int c[200005];
int num[200005];
int d[200005];
int tempc[200005];
int e[200005];
int get(int a , int b)
{
return (a + b - 1) / b ;
}
int p[N] , st[N] , cnt ;
void init(int n)
{
for(int i = 2 ; i <= n ;i ++)
{
if(!st[i]) p[cnt++] = i ;
for(int j = 0 ; p[j] <= n / i ; j ++)
{
st[p[j] * i] = p[j] ;
if(i % p[j] == 0) break;
}
}
}
vector<int> v ;
void get(int x)
{
while(x > 1)
{
int j = st[x] , cc = 0 ;
if(!j)
{
if(x > 1)
{
v.pb(x) ;
}
break ;
}
while(x % j == 0)
{
x /= j ;
cc ++ ;
}
v.pb(j) ;
}
}
bool mysort(int b,int c)
{
return b>c;
}
signed main(){
IOS;
int t;
cin>>t;
while(t--)
{
int flag=1;
int n;
cin>>n;
int temp;
for(int i=0;i<=n;i++)
{
a[i]=0;
b[i]=0;
c[i]=0;
d[i]=0;
e[i]=0;
tempc[i]=0;
}
for(int i=0;i<n;i++)
{
cin>>temp;
a[temp]++;
num[i]=temp;
}
int index=0;
for(int i=1;i<=n;i++)
{
if(a[i]==0)
{
e[index++]=i;
}
}
for(int i=0;i<n;i++)
{
if(a[num[i]]==2)
{
if(d[num[i]]==0)
{
d[num[i]]++;
b[i]=num[i];
int j;
if(index==0)
{
flag=0;
break;
}
else
{
int flag1=1;
for(int k=index-1;k>=0;k--)
{
if(e[k]<num[i]&&e[k]!=0)
{
c[i]=e[k];
tempc[num[i]]=e[k];
if(k==index-1)
index--;
else
e[k]=0;
flag1=0;
break;
}
}
if(flag1)
{
flag=0;
break;
}
}
}
else
{
b[i]=tempc[num[i]];
c[i]=num[i];
}
}
else if(a[num[i]]==1)
{
b[i]=num[i];
c[i]=num[i];
}
else if(a[num[i]]==0)
continue;
else
{
flag=0;
break;
}
}
if(flag==0)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
for(int i=0;i<n;i++)
cout<<b[i]<<" ";
cout<<endl;
for(int i=0;i<n;i++)
cout<<c[i]<<" ";
cout<<endl;
}
}
return 0;
}
/*
*
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/