Game links
\({\frak{A. New Year and Naming}}\)
Modulo can.
\({\frak{code:}}\)
#include<bits/stdc++.h>
#define IL inline
#define LL long long
using namespace std;
const int N=20+3;
int n,m;
string s[N],t[N],ans;
IL int in(){
char c;int f=1;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
int x=c-'0';
while((c=getchar())>='0'&&c<='9')
x=x*10+c-'0';
return x*f;
}
int main()
{
int x,y,z;
n=in(),m=in();
for(int i=1;i<=n;++i) cin>>s[i];
for(int i=1;i<=m;++i) cin>>t[i];
int u=in();
while(u--){
x=in();y=(x-1)%n+1,z=(x-1)%m+1;
ans=s[y]+t[z];
cout<<ans<<endl;
}
return 0;
}
\({\frak{B. New Year and Ascent Sequence}}\)
Each sequence simply save the maximum and minimum, according to whether it satisfies the properties fall into two categories.
Sort, ergodic nature does not meet the set \ (S \) , the current sequence as a sequence left in the \ (S \) in the right sequence of binary search, add answers.
Meet the nature of the collection would not have said it \ (qwq \)
\({\frak{code:}}\)
#include<bits/stdc++.h>
#define IL inline
#define LL long long
using namespace std;
const int N=1e5+3;
struct hh{
int Min,Max,bo;
}a[N];
int n,num,c[N],d[N];
LL ans;
IL int in(){
char c;int f=1;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
int x=c-'0';
while((c=getchar())>='0'&&c<='9')
x=x*10+c-'0';
return x*f;
}
int main()
{
int x,y,z,Max,Min;
n=in();
for(int i=1;i<=n;++i){
x=in(),Max=-1e9,Min=1e9;
for(int j=1;j<=x;++j){
y=in();if(y>Min) a[i].bo=1;
Min=min(Min,y),Max=max(Max,y);
}
a[i].Max=Max,a[i].Min=Min;
if(a[i].bo) ++num;
}
for(int i=1;i<=n;++i) if(!a[i].bo) c[++c[0]]=a[i].Min,d[++d[0]]=a[i].Max;
sort(c+1,c+c[0]+1),sort(d+1,d+d[0]+1);
for(int i=1;i<=c[0];++i){
x=lower_bound(d+1,d+d[0]+1,c[i]+1)-d;
ans+=d[0]-x+1;
}
ans+=1ll*2*num*(n-num)+1ll*num*num;
cout<<ans<<endl;
return 0;
}
\({\frak{C. New Year and Permutation}}\)
Consider length \ (I \) number of sub-strings, the total character set \ (n-i + 1 \ ) species emulated, the number of arrays in the substring \ (I \) \ (! \) , Location \ (ni + 1 \) kind of borrowing, there are other characters \ ((Ni) \) \ (! \) seed row method.
故\(ans=\sum_{i=1}^n{i! \left(n-i \right)! \left(n-i+1 \right)^2}\)。
\({\frak{code:}}\)
#include<bits/stdc++.h>
#define IL inline
#define LL long long
using namespace std;
const int N=25e4+3;
int n,p;
LL ans,fac[N];
IL int in(){
char c;int f=1;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
int x=c-'0';
while((c=getchar())>='0'&&c<='9')
x=x*10+c-'0';
return x*f;
}
int main()
{
n=in(),p=in();
fac[0]=1;for(int i=1;i<=n;++i) fac[i]=fac[i-1]*i%p;
for(int i=1;i<=n;++i) ans=(ans+1ll*(n-i+1)*fac[i]%p*fac[n-i]%p*(n-i+1)%p)%p;
cout<<ans<<endl;
return 0;
}
\({\frak{D. New Year and Conference}}\)
We should respect each in \ (A \) subset of the conflict under, as far as (\ B) \ no-conflict.
Obviously, greedy, we just need to enumerate the two elements can, after sorting the left endpoint complexity is \ (O (number of conflicts) \) .
However, this will be to the card \ (O (^ n-2) \) .
Consider the optimization, the left end is first sorted, enumerate \ (I \) , the first \ (i-1 \) elements, when the \ (ea_k \ GEQ sa_i \) , then \ (I \) and \ (K \) conflicts with \ (I \) element of conflict, if \ (\ EXISTS K \) , so \ (sb_k> eb_i \) or \ (eb_k <sb_i \) , then \ (I \) and \ (K \) does not conflict output \ (nO \) .
So with a heap maintenance, lazy deletion, two sites were swept it again.
Code words. . . In fact, if the write \ (\ frac {1} { 4} \) length like the other \ (fzzt \) .
\({\frak{code:}}\)
#include<bits/stdc++.h>
#define IL inline
#define LL long long
using namespace std;
const int N=1e5+3;
struct hh{
int s,t,id;
bool operator<(const hh &a) const{
return s^a.s?s<a.s:t<a.t;}
}a[N],b[N];
struct k1{
int tim,id;
bool operator<(const k1 &a) const{
return tim<a.tim;}
};
struct k2{
int tim,id;
bool operator<(const k2 &a) const{
return tim>a.tim;}
};
priority_queue<k1>q1;
priority_queue<k2>q2;
int n,p1[N],p2[N],flag;
IL int in(){
char c;int f=1;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
int x=c-'0';
while((c=getchar())>='0'&&c<='9')
x=x*10+c-'0';
return x*f;
}
int main()
{
int x,y,z;
n=in();
for(int i=1;i<=n;++i){
x=in(),y=in(),a[i]=(hh){x,y,i};
x=in(),y=in(),b[i]=(hh){x,y,i};
}
sort(a+1,a+n+1),sort(b+1,b+n+1);
for(int i=1;i<=n;++i) p1[a[i].id]=i,p2[b[i].id]=i;
for(int i=1;i<=n;++i){
x=-1e9,y=2e9;
while(q1.size()){
k1 u=q1.top();
if(a[p1[u.id]].t>=a[i].s){x=u.tim;break;}
q1.pop();
}
while(q2.size()){
k2 u=q2.top();
if(a[p1[u.id]].t>=a[i].s){y=u.tim;break;}
q2.pop();
}
if(x>b[p2[a[i].id]].t||y<b[p2[a[i].id]].s){flag=1;break;}
q1.push((k1){b[p2[a[i].id]].s,a[i].id}),
q2.push((k2){b[p2[a[i].id]].t,a[i].id});
}
while(q1.size()) q1.pop();while(q2.size()) q2.pop();
for(int i=1;i<=n;++i){
x=-1e9,y=2e9;
while(q1.size()){
k1 u=q1.top();
if(b[p2[u.id]].t>=b[i].s){x=u.tim;break;}
q1.pop();
}
while(q2.size()){
k2 u=q2.top();
if(b[p2[u.id]].t>=b[i].s){y=u.tim;break;}
q2.pop();
}
if(x>a[p1[b[i].id]].t||y<a[p1[b[i].id]].s){flag=1;break;}
q1.push((k1){a[p1[b[i].id]].s,b[i].id}),
q2.push((k2){a[p1[b[i].id]].t,b[i].id});
}
puts(flag?"NO":"YES");
return 0;
}