A-Singing Contest

就是两个两个比较,然后用比对手大的最小的去与对手比就行了~

#include"bits/stdc++.h"
#define out(x) cout<<#x<<"="<<x
#define C(n,m) ((long long)fac[(n)]*inv[(m)]%MOD*inv[(n)-(m)]%MOD)
using namespace std;
typedef long long LL;
const int maxn=(1<<16)+5;
const int MOD=1e9+7;
int N,cnt;
struct AAA
{
    int id;
    vector<int>v;
};
AAA a[maxn];
void pushup(int id)
{
    int n=a[id<<1].v.size()-1;
    if(a[id<<1].v[n]<a[id<<1|1].v[n])swap(a[id<<1],a[id<<1|1]);
    int i=n;
    while(a[id<<1].v[i]>a[id<<1|1].v[n])i--;
    a[id<<1].v.erase(a[id<<1].v.begin()+i+1);
    a[id]=a[id<<1];
}
void Build(int id,int L,int R)
{

    if(L==R)
    {
        a[id].id=++cnt;
        for(int j=1;j<=N;j++)
        {
            int t;
            scanf("%d",&t);
            a[id].v.push_back(t);
        }
        sort(a[id].v.begin(),a[id].v.end());
        return ;
    }
    int mid=L+R>>1;
    Build(id<<1,L,mid);
    Build(id<<1|1,mid+1,R);
    pushup(id);
}
int main()
{
    int T;
    scanf("%d",&T);
    for(int Case=1;Case<=T;Case++)
    {
        memset(a,0,sizeof a);
        cnt=0;
        scanf("%d",&N);
        Build(1,1,(1<<N));
        cout<<"Case #"<<Case<<": "<<a[1].id<<endl;
    }
}

J-Heritage of skywalkert

这道题也没懂他啥意思,据说反正就是求出前面几个最大的然后暴力求 l c m 就行了,但是看大佬的写法学到一个新的 s t l 里的函数,

n t h _ e l e m e n t ( a + 1 , a + 1 + K , a + 1 + N )

就是用来找 1 N 里第 K 个小的元素,并且把比他小的放到左边,大的放到右边,据说是 O ( n ) 的复杂度~
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uint;
const int maxn=1e7+5;
const int MOD=1e9+7;
ull a[maxn];
unsigned int X,Y,Z;
ull tang()
{
    X^=X<<16;
    X^=X>>5;
    X^=X<<1;
    ull t=X;
    X=Y;
    Y=Z;
    Z=t^X^Y;
    return Z;
}
ull gcd(ull a,ull b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ull lcm(ull a,ull b)
{
    ull t=a/gcd(a,b);
    return t*b;
}
int main()
{
    int T;
    scanf("%d",&T);
    uint N,A,B,C;
    for(int Case=1;Case<=T;Case++)
    {
        cin>>N>>A>>B>>C;
        X=A,Y=B,Z=C;
        for(int i=1;i<=N;i++)a[i]=tang();
        int K=max(0,(int)N-200);
        nth_element(a+1,a+1+K,a+1+N);//就是这个函数
        ull Max=0;
        for(int i=K+1;i<=N;i++)
        {
            for(int j=i+1;j<=N;j++)
            {
                Max=max(Max,lcm(a[i],a[j]));
            }
        }
        cout<<"Case #"<<Case<<": "<<Max<<endl;
    }
}