老年选手ABC都打不好了,这些题给一年多前的我看都是执掌题……思路都想到但不会写,弱智题也弱智错误百出,这就是上古退役选手的状态……
ABC
签到不解释
D
前缀和,注意long long,因为此问题WA了2发
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n,w,mx; ll s[200200]; int main() { scanf("%d%d",&n,&w); for(int i=1,x,y,z;i<=n;i++) scanf("%d%d%d",&x,&y,&z),mx=max(mx,y),s[x]+=z,s[y]-=z; for(int i=0;i<=mx;i++) { s[i]+=s[i-1]; if(s[i]>w){puts("No");return 0;} } puts("Yes"); }
E
典型的DP,朝着三个方向前缀和优化即可
#include<bits/stdc++.h> using namespace std; const int N=2002,mod=1e9+7; int n,m,f[N][N],s1[N][N],s2[N][N],s3[N][N]; char a[N][N]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)scanf("%s",a[i]+1); f[1][1]=s1[1][1]=s2[1][1]=s3[1][1]=1; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if((i!=1||j!=1)&&a[i][j]=='.') { f[i][j]=(1ll*s1[i-1][j]+s2[i][j-1]+s3[i-1][j-1])%mod; s1[i][j]=(s1[i-1][j]+f[i][j])%mod; s2[i][j]=(s2[i][j-1]+f[i][j])%mod; s3[i][j]=(s3[i-1][j-1]+f[i][j])%mod; } printf("%d",f[n][m]); }
F
一眼就是左偏树+set,但我连map/set指令都忘了,左偏树也不会写,于是就GG了
#include<bits/stdc++.h> using namespace std; const int N=2e5+7; int n,q,fa[N]; map<int,int>mp[N]; int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);} void merge(int x,int y) { x=find(x),y=find(y); if(x==y)return; if(mp[x].size()>mp[y].size())swap(x,y); fa[x]=y; for(auto it:mp[x])mp[y][it.first]+=it.second; mp[x].clear(); } int solve(int x,int y){x=find(x);return mp[x].count(y)?mp[x][y]:0;} int main() { scanf("%d%d",&n,&q); for(int i=1,x;i<=n;i++)scanf("%d",&x),mp[i][x]=1,fa[i]=i; while(q--) { int tp,x,y;scanf("%d%d%d",&tp,&x,&y); if(tp==1)merge(x,y);else printf("%d ",solve(x,y)); } }
rank809 rating+=67 小号打的