2018杭电多校第八场

A

#include 
#include 
#include 
using namespace std;
const int MAXN = 202020;
const int MOD = 998244353;
int fac[MAXN], facinv[MAXN];
int n, m, k;
long long quickmul(int a, int b)
{
    long long ret = 1;
    for(; b; b >>= 1, a = (long long)a * a % MOD)
        if(b & 1)
            ret = ret * a % MOD;
    return ret;
}
void init()
{
    fac[0] = 1;
    for(int i = 1; i < MAXN; i++)
        fac[i] = (long long)fac[i - 1] * i % MOD;
    facinv[MAXN - 1] = quickmul(fac[MAXN - 1], MOD - 2);
    for(int i = MAXN - 1; i > 0; i--)
        facinv[i - 1] = (long long) facinv[i] * i % MOD;
}
long long C(int n, int m)
{
    if(n < 0 || m < 0 || m > n)
        return 0;
    return (long long)fac[n] * facinv[m] % MOD * facinv[n - m] % MOD;
}
void solve()
{
    scanf("%d%d%d", &n, &m, &k);
    int ans = 0;
    for(int c = 0; c * n <= k; c++)
    {
        if(c & 1)
            ans = (ans - C(m, c) * C(k - c * n + m - 1, m - 1) % MOD + MOD) % MOD;
        else
            ans = (ans + C(m, c) * C(k - c * n + m - 1, m - 1)) % MOD;
    }
    printf("%d\n", ans);
}
int main()
{
    init();
    int T;
    for(scanf("%d", &T); T; T--)
        solve();
    return 0;
}

D

#include 
using namespace std;
#define rep(i,a,n) for (int i=a;i=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector VI;
typedef long long ll;
typedef pair PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

/*
int n,m,a[10][10],ans;

void dfs(int u,int v) {
    if (u==n) {
        int cnt=0;
        rep(i,0,n) {
            int c=0; bool val=1;
            rep(j,0,m) {
                c+=a[i][j];
                val&=c>=0;
            }
            val&=c==0;
            cnt+=val;
        }
        rep(i,0,m) {
            int c=0; bool val=1;
            rep(j,0,n) {
                c+=a[j][i];
                val&=c>=0;
            }
            val&=c==0;
            cnt+=val;
        }
        if (cnt>ans) {
            ans=cnt;
            printf("%d\n",ans);
            rep(i,0,n) rep(j,0,m) printf("%d%c",a[i][j]," \n"[j==m-1]);
        }
    } else {
        a[u][v]=1;
        dfs(u+(v+1)/m,(v+1)%m);
        a[u][v]=-1;
        dfs(u+(v+1)/m,(v+1)%m);
    }
}
int main() {
    scanf("%d%d",&n,&m);
    dfs(0,0);
}
*/

int _,n,m,f[210][210];
int main() {
    for (scanf("%d",&_);_;_--) {
        scanf("%d%d",&n,&m);
        if (n%2==1&&m%2==1) {
            rep(i,0,n) {
                rep(j,0,m) putchar('(');
                puts("");
            }
        } else if (n%2==0&&m%2==1) {
            rep(i,0,n/2) {
                rep(j,0,m) putchar('(');
                puts("");
            }
            rep(i,0,n/2) {
                rep(j,0,m) putchar(')');
                puts("");
            }
        } else if (n%2==1&&m%2==0) {
            rep(i,0,n) {
                rep(j,0,m/2) putchar('(');
                rep(j,0,m/2) putchar(')');
                puts("");
            }
        } else {
            int p=min(n,m),q=max(n,m);
            if (p<=4) {
                rep(i,0,p) {
                    rep(j,0,q/2) f[i][j]=i&1;
                    rep(j,0,q/2) f[i][j+q/2]=(i&1)^(i!=0&&i!=p-1);
                }
                if (n

E

#include 
using namespace std;
#define rep(i,a,n) for (int i=a;i=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector VI;
typedef long long ll;
typedef pair PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int _,n;
char s[10][10],t[10];
int main() {
    for (scanf("%d",&_);_;_--) {
        scanf("%d",&n);
        rep(i,0,3) scanf("%s",s[i]);
        rep(i,0,n) {
            scanf("%s",t);
            int x=(t[0]-'1')/2;
            int y=(t[0]-'1')%2;
            int c=t[1]=='R'?3:1;
            rep(j,0,c) {
                swap(s[x][y],s[x+1][y]);
                swap(s[x+1][y],s[x+1][y+1]);
                swap(s[x+1][y+1],s[x][y+1]);
            }
        }
        rep(i,0,3) puts(s[i]);
    }
}

#include
#include 
#include 
#include 
#include  
#include   
#include   
#include   
#include   
#include    
#include      
#include      
using namespace std;

const int N=100005,M=6000005;

int n,m,h[N],fa[N],dis[N],ha[N],num[N],lc[M],rc[M],Min[M],rt[N],tot;

void Ins(int& x,int l,int r,int p,int v)
{
    int y=++tot;lc[y]=lc[x];rc[y]=rc[x];Min[y]=min(Min[x],v);x=y;
    if(l==r)
        return;
    int Mid=l+r>>1;
    if(p<=Mid)
        Ins(lc[x],l,Mid,p,v);
    else
        Ins(rc[x],Mid+1,r,p,v);
}

int getMin(int x,int l,int r,int p)
{
    if(!x||p>r)
        return n+1;
    if(p<=l)
        return Min[x];
    int Mid=l+r>>1;
    if(p<=Mid)
        return min(getMin(lc[x],l,Mid,p),getMin(rc[x],Mid+1,r,p));
    return getMin(rc[x],Mid+1,r,p);
}

void solve()
{
    scanf("%d%d",&n,&m);
    Min[0]=n+1;
    for(int i=1;i<=n;i++)
        scanf("%d",&h[i]),ha[i]=num[i]=0;
    rt[n+1]=0;tot=0;dis[n+1]=0;
    for(int i=n;i;i--)
    {
        fa[i]=getMin(rt[i+1],1,1e9,h[i]+1),rt[i]=rt[i+1],Ins(rt[i],1,1e9,h[i],i);
        dis[i]=dis[fa[i]]+1;
    }
    int t1=1,t2=1;
    while(t1!=n+1)
    {
        ha[t1]=t1;num[t1]=t2;
        t1=fa[t1];t2++;
    }
    for(int i=1;i<=n;i++)
        if(!ha[i])
            ha[i]=ha[i-1],num[i]=num[i-1];
    while(m--)
    {
        int x,cx;scanf("%d%d",&x,&cx);
        if(x==1)
        {
            int nxt=getMin(rt[2],1,1e9,cx+1);
            printf("%d\n",1+dis[nxt]);
        }
        else
        {
            int pre=ha[x-1];
    //        cout<h[pre])
                    printf("%d\n",num[x]+dis[getMin(rt[x+1],1,1e9,cx+1)]);
                else
                    printf("%d\n",num[pre]+dis[getMin(rt[x+1],1,1e9,h[pre]+1)]);
            }
            else
            {
                if(cx>h[pre])
                    printf("%d\n",1+num[x]+dis[getMin(rt[x+1],1,1e9,cx+1)]);
                else
                    printf("%d\n",num[n]);
            }
        }
    }
}

int main()
{
    int t;cin>>t;
    while(t--)
        solve(); 
    return 0;
}

 

你可能感兴趣的:(2018杭电多校第八场)