Codeforces Round #651 (Div. 2)(A,B,C,D,E)

#include
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e4+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
/*
A题
*/
int t,n;
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>t;
    while(t--){
        cin>>n;
        cout<
#include
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=2100;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
/*
B题
*/
int t,n,a[maxn],cnt[2];
pii p[maxn];
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>t;
    while(t--){
        mst(cnt,0);
        cin>>n;
        rep(i,1,2*n+1){
            cin>>a[i];
            a[i]%=2;
            cnt[a[i]]++;
            p[i]=mk(a[i],i);
        }
        sort(p+1,p+2*n+1);
        if(cnt[1]&1){
            for(int i=1;i<=2*n;i+=2){
                if(p[i].fi^p[i+1].fi) continue;
                cout<
#include
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e4+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
/*
C题
*/
int t;
ll n;
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>t;
    while(t--){
        cin>>n;

        if(n==1) {cout<<"FastestFinger\n";continue;}
        if(n&1) {cout<<"Ashishgup\n";continue;}

        int tmp=0,cnt=0;
        while(n%2==0) n/=2,tmp++;

        for(int i=3;1LL*i*i<=n;i++)
            while(n%i==0) n/=i,cnt++;
        if(n!=1) cnt++;       

        tmp=(tmp==1);
        if(!tmp){
            if(cnt) cout<<"Ashishgup\n";
            else cout<<"FastestFinger\n";
        }else{
            if(cnt!=1) cout<<"Ashishgup\n";
            else cout<<"FastestFinger\n";
        }
    }
    return 0;
}
#include
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=2e5+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
/*
D题
*/
int n,k,a[maxn],b[maxn];
int judge(int x){
    int cnt1=0,cnt0=0;
    rep(i,1,n+1){
        if(a[i]<=x){
            cnt1++;
            if(i+1<=n) cnt0++,i++;
        }
    }
    if(cnt0>=k/2&&cnt1>=(k+1)/2) return 1;
    cnt1=1,cnt0=0;
    rep(i,2,n+1){
        if(a[i]<=x){
            cnt0++;
            if(i+1<=n) cnt1++,i++;
        }
    }
    if(cnt1>=(k+1)/2&&cnt0>=k/2) return 1;
    return 0;
}
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>n>>k;
    rep(i,1,n+1){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b+1,b+1+n);
    int cnt=unique(b+1,b+1+n)-b-1;
    int l=1,r=cnt,ans;
    while(l<=r){
        int mid=l+r>>1;
        if(judge(b[mid])){
            r=mid-1,ans=mid;
        }else{
            l=mid+1;
        }
    }
    cout<
#include
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair
#define fi first                                  
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=1e6+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
/*
E题
*/
int n,cnt0=0,cnt1=0,ret=0,cur;
int sk[maxn],idx=0,l1=0,l2=0;
string s,t;
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>n;ret=0;
    cin>>s>>t;
    rep(i,0,n) if(s[i]^t[i]){
        if(s[i]=='0'){
            cnt0++,cur=0;
        }else{
            cnt1++,cur=1;
        }
        if(idx==0) sk[idx++]=cur;
        else{
            if(sk[idx-1]^cur) idx--;
            else sk[idx++]=cur;
        }
        if(idx){
            if(sk[idx-1]) l1=max(l1,idx);
            else l2=max(l2,idx);
        }
    }
    if(cnt0^cnt1) cout<<"-1\n";
    else cout<

 

 

 

 

 

你可能感兴趣的:(各种题解,Codeforces习题集)