# Hello 2020

QAQ：这场比赛打了，A掉三题，挺快乐的，希望今年比赛成绩能好一点，Hello 2020

## A. New Year and Naming

#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
string s[maxn],t[maxn];
int main()
{
int n ,m;
cin >> n >> m;
for(int i  = 0;i<n;i++)
cin >> s[i];
for(int i = 0;i<m;++i)
cin >> t[i];
int q,x;
cin >> q;
while(q--)
{
int x;
cin >> x;
cout << s[(x-1)%n] << t[(x-1)%m] << endl;
}
return 0;
}

## B. New Year and Ascent Sequence

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int num[maxn];
int  A[maxn],B[maxn];
typedef long long LL;
int main()
{

LL cnt = 0;
int n,len = 0;
scanf("%d",&n);
for(int k = 0;k<n;k++)
{
int l;
scanf("%d",&l);
for(int i = 0;i<l;i++)
{
scanf("%d",&num[i]);
}
int ma,mi;
ma =mi = num[0];
bool flag = false;
num[l] = num[l-1];
for(int i = 0;i<l;++i)
{
ma = max(num[i],ma);
mi = min(num[i],mi);
if(num[i]<num[i+1])
{
//if(!flag)
flag = true;
}
}
if(flag)
cnt++;
else
{
A[len] = mi;
B[len++] = ma;
}
//  cout << len << endl;
}
sort(A,A+len);
sort(B,B+len);
LL sum = 0;
for(int i = 0;i<len;++i)
{
int d = upper_bound(B,B+len,A[i]) - B;
//cout << A[i] << " " << d << endl;
sum +=(len-d);
}
//cout << cnt << " " << sum << endl;
cout << cnt*(LL)n+((LL)n-cnt)*cnt+sum << endl;
return 0;
}

## C. New Year and Permutation

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn  = 250000+50;
LL num[maxn];
void getf(LL n,LL m)
{
num[0]  = 1;
for(int i = 1;i<=n;i++)
{
num[i] = (i*(num[i-1]))%m;
}
return ;
}
int main()
{
LL n,m;
cin >> n >> m;
getf(n,m);
LL ans = 0;
LL sum;
for(int i = 1;i<=n;i++)
{
sum = (n+1-i)*(n+1-i);
sum%=m;
sum  = (sum*num[i])%m;
sum = (sum*(num[n-i]))%m;
ans = (ans+sum)%m;
//cout << ans << endl;
}
cout << ans << endl;

return 0;
}

## D. New Year and Conference

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int maxn = 1e5+100;
struct node
{
int sa,ea,sb,eb;
node(){}
node(int a,int b,int c,int d):sa(a),ea(b),sb(c),eb(d){}
bool operator <(node b)const
{
if(sa==b.sa) return ea<b.ea;

return    sa<b.sa;
}
}p[maxn];
int mx[4*maxn],mi[4*maxn];
void creat(int l,int r,int k)
{
if(l==r)
{
mx[k] = p[l].sb,mi[k] =p[l].eb;
return ;
}
int mid = (l+r)/2;
creat(l,mid,2*k);
creat(mid+1,r,2*k+1);
mx[k] = max(mx[2*k],mx[2*k+1]);
mi[k] = min(mi[2*k],mi[2*k+1]);
}
int querymin(int l,int r,int al,int ar,int k)
{
if(l==al&&r==ar) return mi[k];
int mid=(l+r)/2;
if(ar<=mid) return querymin(l,mid,al,ar,2*k);
else if(al>mid) return querymin(mid+1,r,al,ar,2*k+1);
else return min(querymin(l,mid,al,mid,2*k),querymin(mid+1,r,mid+1,ar,2*k+1));

}
int querymax(int l,int r,int al,int ar,int k)
{
if(l==al&&r==ar) return mx[k];
int mid = (l+r)/2;
if(ar<=mid) return querymax(l,mid,al,ar,2*k);
else if(al>mid) return querymax(mid+1,r,al,ar,2*k+1);
else return max(querymax(l,mid,al,mid,2*k),querymax(mid+1,r,mid+1,ar,2*k+1));
}
bool solve(int n)
{
sort(p+1,p+1+n);
creat(1,n,1);
for(int i = 1;i<=n;++i)
{
int pos = lower_bound(p+1,p+1+n,node(p[i].ea,1e9+1000,0,0))-p-1;
if(!(i+1<=pos)) continue;
if(querymin(1,n,i+1,pos,1)<p[i].sb||querymax(1,n,i+1,pos,1)>p[i].eb)
return false;
}
return true;
}
int main()
{
int n,i,j,l,sig = 1;
scanf("%d",&n);
for(i  = 1;i<=n;++i)
{
scanf("%d%d%d%d",&p[i].sa,&p[i].ea,&p[i].sb,&p[i].eb);

}
sig&=solve(n);
for(i = 1;i<=n;++i)
swap(p[i].sa,p[i].sb),swap(p[i].ea,p[i].eb);
sig&=solve(n);
if(sig) printf("YES\n");
else printf("NO\n");
return 0;
}

posted @ 2020-01-14 17:41  浅花迷人  阅读(65)  评论(0编辑  收藏