H(模拟):
#include<bits/stdc++.h>
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 root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#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 ub=1e6;
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;}
int gcd(int x,int y){ return y?gcd(y,x%y):x;}
ll a,b,c,d;
pii tmp[maxn];
int cnt=0;
ll solve(ll x,ll y){ll ans=0;rep(i,0,cnt){int p=tmp[i].fi,q=tmp[i].se;ans+=min(x/p,y/q);ans+=min(x/q,y/p);}ans+=min(x,y);return ans;
}
int main(){ios::sync_with_stdio(false);rep(i,1,999) rep(j,i+1,999) if(gcd(i,j)==1&&i+j<=999) tmp[cnt++]=mk(i,j);cin>>a>>b>>c>>d;cout<<solve(b,d)-solve(a-1,d)-solve(b,c-1)+solve(a-1,c-1)<<'\n';return 0;
}
L(记忆化+数组链表):
#include<bits/stdc++.h>
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 root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=1e5+10;
const int ub=1e6;
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;}
int gcd(int x,int y){ return y?gcd(y,x%y):x;}
int n,a[maxn],nxt[maxn][2];
int x,tmp,pos,cnt=0,val=0;
int ans1[maxn],ans2[maxn];
int main(){mst(ans1,-1);scanf("%d",&n);rep(i,1,n+1) scanf("%d",&a[i]);nxt[n][0]=nxt[n][1]=n;for(int i=n-1;i>=1;i--){if(a[i]<=a[i+1]){nxt[i][0]=nxt[i+1][0];nxt[i][1]=i;}else{nxt[i][1]=nxt[i+1][1];nxt[i][0]=i;}}int ca;scanf("%d",&ca);rep(i,0,ca){cnt=val=0;scanf("%d",&x);if(ans1[x]!=-1) printf("%d %d\n",ans1[x],ans2[x]);else{for(int i=1;i<=n;i=pos+1,cnt++){if(nxt[i][0]>nxt[i][1]){pos=nxt[i][0];}else{pos=nxt[i][1];}tmp=min(n,i+x-1);if(tmp>pos){val+=tmp-pos;pos=tmp;}}ans1[x]=cnt,ans2[x]=val;printf("%d %d\n",cnt,val);}}return 0;
}
H(博弈SG函数):
#include<bits/stdc++.h>
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 root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e3+10;
const int ub=1e6;
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;}
int gcd(int x,int y){ return y?gcd(y,x%y):x;}
int sg[maxn],s[maxn],mark=0;
int main(){sg[0]=sg[1]=0;rep(i,2,maxn){mark++;int flag=0;rep(j,0,i-1) s[sg[j]^sg[i-2-j]]=mark;while(s[flag]==mark) flag++;sg[i]=flag;}int t;scanf("%d",&t);while(t--){int x;scanf("%d",&x);if(sg[x]) puts("First");else puts("Second");}return 0;
}