【唐赛】高一小学期2
纯唐比赛
\[不唐我都不带写的
\]
\[\LARGE 真正的唐赛,你值得一冲!
\]
没啥看的
T1 同类分布
一眼数位DP,没啥好嗦的
但是,题面出锅,本来数据范围给的是 \(2^{31}\) ,结果考完一看测试数据 \(1 1000000000000000000\),照搬洛谷就算了吧,时限还抄错(洛谷3000ms 考试时1000ms) 我真的***** 你猜我为啥T1 90分
#include<bits/stdc++.h>
using namespace std;
#define rd read()
#define int long long
int read(){
int f=1,x=0;
char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return f*x;
}
int l,r,f[20][200][200];
int len,a[20],mod;
int dfs(int pos,int sum,int num,int limit){
if(pos==0) return sum==0?0:(sum==mod && num%mod==0);
if(pos>len) return num==0 && sum==mod?1:0;
if(!limit && f[pos][sum][num]!=-1) return f[pos][sum][num];
int res=limit?a[len-pos+1]:9,ret=0;
for(int i=0;i<=res && i+sum<=mod;i++)
ret+=dfs(pos+1,sum+i,(10ll*num+i)%mod,i==res && limit);
return limit?ret:f[pos][sum][num]=ret;
}
int part(int x){
if(!x) return 0;
len=0;
while(x){
a[++len]=x%10;
x/=10;
}
int ret=0;
for(mod=1;mod<=9*len;mod++){
memset(f,-1,sizeof(f));
ret+=dfs(1,0,0,1);
}
return ret;
}
signed main(){
#ifdef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
l=rd,r=rd;
printf("%lld\n",part(r)-part(l-1));
return 0;
}
T2 千山鸟飞绝
讨厌数据结构,所以直接去打暴力了
赛时暴力打锅了,没调出来
还有个原因,他TM T2 的题输入文件还是a.in a.out
(T1 也是a.in a.out
),由于惯性思维我TM一直以为是b.in b.out
,直到刚不久别人告诉我我TM才发现
赛后暴力 70pts
#include<bits/stdc++.h>
using namespace std;
#define rd read()
#define int long long
#define mkp make_pair
int read(){
int f=1,x=0;
char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return f*x;
}
const int N=300100;
struct Node{
int x,y,z,u,v;
}bd[N];
struct Q{
int v,x,y;
}q[N];
int n,T,cnt;
multiset<int>s1[N],s2[N];
int vis[N];
map< pair<int,int> ,int>mp;
void update(int x){
multiset<int>::iterator it;
it=s2[x].begin();
int len=s1[x].size();
if(len==1||len==0) return ;
while(it!=s2[x].end()){
s1[x].erase(bd[*it].z);
bd[*it].u=max(bd[*it].u,len-1),bd[*it].v=max(bd[*it].v,(int)*(--s1[x].end()));
s1[x].insert(bd[*it].z);
it++;
}
}
signed main(){
#ifdef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=rd;
for(int i=1;i<=n;i++){
bd[i].z=rd,bd[i].x=rd,bd[i].y=rd;
int t=mp[mkp(bd[i].x,bd[i].y)];
if(!t){
t=++cnt;
mp[mkp(bd[i].x,bd[i].y)]=t;
}
s1[t].insert(bd[i].z),s2[t].insert(i);
}
for(int i=1;i<=n;i++){
int t=mp[mkp(bd[i].x,bd[i].y)];
s1[t].erase(bd[i].z);
if(s1[t].empty()){
s1[t].insert(bd[i].z);
continue;
}
bd[i].u=s1[t].size();
bd[i].v=*--s1[t].end();
s1[t].insert(bd[i].z);
}
T=rd;
for(int i=1;i<=T;i++)
q[i].v=rd,q[i].x=rd,q[i].y=rd;
for(int i=1;i<=T;i++){
int v=q[i].v,x=q[i].x,y=q[i].y;
int t=mp[mkp(bd[v].x,bd[v].y)];
if(vis[t]){
update(t);
vis[t]=0;
}
s1[t].erase(bd[v].z),s2[t].erase(v);
if(s1[t].empty())
mp[mkp(bd[v].x,bd[v].y)]=0;
t=mp[mkp(x,y)];
bd[v].x=x,bd[v].y=y;
if(s1[t].empty())t=0;
if(t){
bd[v].u=max(bd[v].u,(int)s1[t].size());
bd[v].v=max(bd[v].v,(int)*--s1[t].end());
}else{
t=++cnt;
mp[mkp(x,y)]=t;
}
s1[t].insert(bd[v].z);
s2[t].insert(v);
vis[t]=1;
}
for(int i=1;i<=n;i++){
update(mp[mkp(bd[i].x,bd[i].y)]);
printf("%lld\n",1ll*bd[i].u*bd[i].v);
}
return 0;
}
/*
5
1 1 1
3 1 2
4 4 4
2 0 1
2 2 3
5
1 1 2
2 4 4
2 4 3
3 0 1
5 0 1
*/
multiset是真的好用
\(\LARGE STL真香\)
贺题解,平衡树Splay
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rd read()
#define inf 0x3f
#define INF 0x3f3f3f3f3f3f3f3f
#define mst(a,b) memset((a),(b),sizeof((a)))
#define mkp make_pair
#define Elaina 0
inline int read(){
int x=0,f=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return x*f;
}
const int N=3e5+100;
int w[N],num,a[N];
int lz1[N],lz2[N],ans1[N],ans2[N];
int q[N];
map< pair<int,int> ,int> vis;
struct Slpay{
int rt,tot,fa[N],ch[N][2],val[N],rot[N],sz[N];
int get(int x) {return x==ch[fa[x]][1];}
void clear(int x) {ch[x][1]=ch[x][0]=sz[x]=fa[x]=val[x]=lz1[x]=lz2[x]=0;}
void pushup(int x){
sz[x]=sz[ch[x][1]]+sz[ch[x][0]]+1;
val[x]=max(max(val[ch[x][1]],val[ch[x][0]]),w[x]);
}
void rotate(int x){
int y=fa[x],z=fa[y],type=get(x);
ch[y][type]=ch[x][type^1];
fa[ch[x][type^1]]=y;
ch[x][type^1]=y;
fa[y]=x,fa[x]=z;
if(z) ch[z][y==ch[z][1]]=x;
pushup(y),pushup(x);
}
void pushdown(int x){
int k1=lz1[x],k2=lz2[x];
for(int i=0;i<=1;i++){
if(ch[x][i]){
int j=ch[x][i];
ans1[j]=max(ans1[j],k1);
ans2[j]=max(ans2[j],k2);
lz1[j]=max(lz1[j],k1);
lz2[j]=max(lz2[j],k2);
}
}
lz1[x]=lz2[x]=0;
}
void splay(int x,int &rt){
int top=0;
for(int f=x;f;f=fa[f]) q[++top]=f;
while(top) pushdown(q[top--]);
for(int f;f=fa[x];rotate(x))
if(fa[f])
rotate(get(f)==get(x)?f:x);
rt=x;
}
int find_pre(int p){
int now=ch[rot[p]][0];
while(ch[now][1]) now=ch[now][1];
return now;
}
void del(int p,int x){
splay(x,rot[p]);
int now=rot[p];
if(!ch[now][0]&&!ch[now][1]){
clear(now);
rot[p]=0;
return;
}
for(int i=0;i<=1;i++){
if(!ch[now][i]){
rot[p]=ch[now][i^1];
fa[rot[p]]=0;
clear(now);
return;
}
}
x=find_pre(p);
splay(x,rot[p]);
fa[ch[now][1]]=x;
ch[x][1]=ch[now][1];
clear(now);
pushup(rot[p]);
}
void insert(int &p,int x,int f){
if(!p){
p=x,fa[p]=f,val[p]=w[p],sz[p]=1;
return;
}
pushdown(p);
if(!ch[p][0]) insert(ch[p][0],x,p);
else insert(ch[p][1],x,p);
}
}tr;
signed main(){
#ifdef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
int n=rd;
for(int i=1;i<=n;i++){
w[i]=rd;
int x=rd,y=rd;
if(!vis.count(mkp(x,y))) vis[mkp(x,y)]=++num;
int k=vis[mkp(x,y)];
a[i]=k;
ans1[i]=max(ans1[i],tr.val[tr.rot[k]]);
ans2[i]=max(ans2[i],tr.sz[tr.rot[k]]);
tr.insert(tr.rot[k],i,0);
tr.splay(i,tr.rot[k]);
lz1[tr.rot[k]]=max(lz1[tr.rot[k]],w[i]);
lz2[tr.rot[k]]=max(lz2[tr.rot[k]],tr.sz[tr.rot[k]]-1);
}
int t=read();
while(t--){
int i=rd,x=rd,y=rd;
if(!vis.count(mkp(x,y))) vis[mkp(x,y)]=++num;
int k=vis[mkp(x,y)],pre=a[i];
a[i]=k;
tr.del(pre,i);
ans1[i]=max(ans1[i],tr.val[tr.rot[k]]);
ans2[i]=max(ans2[i],tr.sz[tr.rot[k]]);
tr.insert(tr.rot[k],i,0);
tr.splay(i,tr.rot[k]);
lz1[tr.rot[k]]=max(lz1[tr.rot[k]],w[i]);
lz2[tr.rot[k]]=max(lz2[tr.rot[k]],tr.sz[tr.rot[k]]-1);
}
for(int i=1;i<=n;i++){
tr.splay(i,tr.rot[a[i]]);
printf("%lld\n",1ll*ans1[i]*ans2[i]);
}
return Elaina;
}