9.24赛后总结

· · 个人记录

成绩:

(题目按做题顺序排列) ## T1: 没什么头绪,于是玄学打暴力找规律,也没找到什么规律,于是直接暴力就跳过了。 正解:DP+费马小定理 ```cpp #include<bits/stdc++.h> using namespace std; using LL=long long; const int N=1e5+5,M=998244353; int n; LL f[N]; LL C(LL x,LL y){ LL r=1; for(;y;x=x*x%M,y>>=1){ y&1&&(r=r*x%M); } return r; } int main(){ freopen("set.in","r",stdin); freopen("set.out","w",stdout); cin>>n,f[0]=1; for(int i=1;i<=n;i++){ for(int j=i*(i+1)/2;j>=i;j--){ f[j]=(f[j]+f[j-i])%(M-1); } } LL s=1; for(int i=1;i<=n*(n+1)/2;i++){ s=s*C(i,f[i])%M; } cout<<s; return 0; } ``` ## T3: 想到了正解,但又在实现过程中出现了一些奇♂奇♀怪♂怪♀的问题,于是打了暴力。 [代码有点抽象,谨慎观看](https://www.luogu.com.cn/paste/5yv7vsjd) ## T2: 想了一会儿,不知道每一次的的人要放在哪里、能不能住下怎么判断。于是直接 $O(mn\log n)$ 暴力模拟,每次从左往右将人们填入,判断是否能填下。 $20$ pts 暴力 $\rArr$ $30$ pts。 ```cpp #include<bits/stdc++.h> using namespace std; using Pii=pair<int,int>; const int N=5e5+5; int n,m,k,d,l[N]; vector<Pii>a; int main(){ freopen("hire.in","r",stdin); freopen("hire.out","w",stdout); cin>>n>>m>>k>>d; for(int x,y;m;m--){ cin>>x>>y; if(y>0){ if(a.size()){ int p=lower_bound(a.begin(),a.end(),make_pair(x,0))-a.begin(); if(a[p].first==x){ a[p].second+=y; }else{ a.push_back({x,y}); } }else{ a.push_back({x,y}); } }else{ int p=lower_bound(a.begin(),a.end(),make_pair(x,0))-a.begin(); a[p].second+=y; } sort(a.begin(),a.end()); bool f=1; fill(l+1,l+n+1,k); for(auto h:a){ int x=h.first,y=h.second; for(int i=x;i<=x+d&&y;i++){ l[i]>=y?(l[i]-=y,y=0):(y-=l[i],l[i]=0); } if(y){ f=0; break; } } cout<<(f?"YES":"NO")<<"\n"; } return 0; } ``` 正解:线段树维护最大字段和。 ```cpp #include<bits/stdc++.h> using namespace std; using LL=long long; const int N=5e5+5; int n,m; LL k,d; struct O{ LL s,l,r,v; }t[N<<2]; void P(int u){ t[u].s=t[2*u].s+t[2*u+1].s; t[u].l=max(t[2*u].l,t[2*u].s+t[2*u+1].l); t[u].r=max(t[2*u].r+t[2*u+1].s,t[2*u+1].r); t[u].v=max({t[2*u].v,t[2*u+1].v,t[2*u].r+t[2*u+1].l}); } void B(int u,int l,int r){ if(l==r){ t[u].s=t[u].v=-k; return; } int p=l+r>>1; B(2*u,l,p),B(2*u+1,p+1,r),P(u); } void U(int u,int l,int r,int x,LL y){ if(l>x||r<x){ return; } if(l==x&&r==x){ t[u].v+=y; t[u].l=t[u].r=max(t[u].s+=y,0ll); return; } int p=l+r>>1; U(2*u,l,p,x,y); U(2*u+1,p+1,r,x,y); P(u); } int main(){ freopen("hire.in","r",stdin); freopen("hire.out","w",stdout); ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n>>m>>k>>d; B(1,1,n); for(LL x,y;m;m--){ cin>>x>>y; U(1,1,n,x,y); cout<<(t[1].v<=k*d?"YES":"NO")<<"\n"; } return 0; } ``` ## T4: 没太看懂题,然后就摆了。