题解:
1.
二分答案之后判断
把式子移项使得x,y不关联
#include <bits/stdc++.h> using namespace std; #define rint register int #define IL inline #define rep(i,h,t) for (rint i=h;i<=t;i++) #define dep(i,t,h) for (rint i=t;i>=h;i--) const int N=3e5; int a[N],sum[N],n,m; const int INF=1e9; bool check(int x) { sum[0]=0; int mina=-INF; rep(i,1,n) { if (a[i]<x) sum[i]=sum[i-1]+1; else sum[i]=sum[i-1]; if (i-m+1>0) mina=max(mina,2*sum[i-m]-(i-m+1)); if (2*sum[i]-i<=mina) return(1); } return(0); } int main() { freopen("1.in","r",stdin); freopen("1.out","w",stdout); ios::sync_with_stdio(false); cin>>n>>m; rep(i,1,n) cin>>a[i]; int h=0,t=INF; while (h<t) { int mid=(h+t+1)>>1; if (check(mid)) h=mid; else t=mid-1; } cout<<h<<endl; return 0; }
2.
数位dp
考虑10个数字一共有18个
C(27,9) 算一下发现不大
然后就直接记忆化搜索就行了
数比较大可以用map记录
但好像比较慢于是改了hash
然后有3个点是考细节的
后面两个是map如果初值为0就炸了 可能之后一直为0 因为y可以是-1
另外一个是0要特殊考虑dfs(0)
#include <bits/stdc++.h> using namespace std; #define rint register int #define IL inline #define rep(i,h,t) for (rint i=h;i<=t;i++) #define dep(i,t,h) for (rint i=t;i>=h;i--) #define ll long long #define mp(x,y) make_pair(x,y) ll l,n,m,f[100]; int cnt=0; const int mo=6e6+7; struct re{ bool a,b; short c; ll d,ans; }hs[mo+1000]; queue<int> q; struct hash{ ll find(bool a,bool b,short x,ll y) { int t1=((1ll*x%mo*y%mo)%mo+mo)%mo; while (hs[t1].c&&!(hs[t1].a==a&&hs[t1].b==b&&hs[t1].c==x&&hs[t1].d==y)) t1++,cnt++; if (hs[t1].c) return(hs[t1].ans); return(-1); } void insert(bool a,bool b,short x,ll y,ll ans) { int t1=((1ll*x%mo*y%mo)%mo+mo)%mo; while (hs[t1].c) t1++,cnt++; hs[t1].a=a; hs[t1].b=b; hs[t1].c=x; hs[t1].d=y; hs[t1].ans=ans; q.push(t1); } void clear() { while (!q.empty()) { int x=q.front(); q.pop(); hs[x].c=hs[x].ans=0; } } }M; ll dfs(short x,ll y,bool z,bool kk) { cnt++; ll ans1=M.find(z,kk,x,y); if (ans1!=-1) return(ans1); if (x==l+1) { if (kk==1) y=0; if (y<=m) { return(1); } return(0); } ll ans=0; rep(i,0,9) if (i==0&&kk==1) ans+=dfs(x+1,1,0,1); else { if (z==1) { if (i<f[x]) ans+=dfs(x+1,y*i,0,0); if (f[x]==i) ans+=dfs(x+1,y*i,1,0); } else ans+=dfs(x+1,y*i,0,0); } M.insert(z,kk,x,y,ans); return(ans); } ll js(ll x,ll y) { if (x<0) return(0); M.clear(); ll tmp=x; l=0; if (x==0) l=1,f[1]=0; while (tmp) l++,f[l]=tmp%10,tmp/=10; reverse(f+1,f+l+1); m=y; return dfs(1,1,1,1); } int main() { ios::sync_with_stdio(false); ll x1,x2,y1,y2; cin>>x1>>x2>>y1>>y2; cout<<js(x2,y2) -js(x2,y1-1)- (js(x1-1,y2)- js(x1-1,y1-1))<<endl; return 0; }
3.