摘要: 这题在修改的时候略有不同,应当减去之前的贡献再加上此时的贡献。 就像这样: void add(int x){ now=now+2*cnt[a[x]]+1; cnt[a[x]]++; } void del(int x){ cnt[a[x]]--; now=now-2*cnt[a[x]]-1; } 那么 阅读全文
posted @ 2020-03-11 22:12 syzf2222 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 这几乎就是莫队板子。 是否互不相同等价于判断 now==q[i].r-q[i].l+1 。 看代码: #include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; int n,m,a[maxn],cnt[maxn],ans[m 阅读全文
posted @ 2020-03-11 22:09 syzf2222 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 如果要学习莫队算法请另寻别处。 但是这里可以为您提供高质量的练习题配代码。 代码如下: #include<bits/stdc++.h> using namespace std; const int maxn=1e6+10; struct node{ int l,r,bl,br,id; }q[maxn 阅读全文
posted @ 2020-03-11 22:07 syzf2222 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 这题需要把状转方程想清楚,在动手打代码。 可能大多数人像我一样第一反应是这样的: f[x][0]=0,f[x][1]=1; for(int i=beg[x];i;i=nex[i]) if(to[i]!=fa){ dfs(to[i],x); f[x][0]+=f[to[i]][1]; f[x][1]+ 阅读全文
posted @ 2020-03-11 12:34 syzf2222 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 我觉得我好像已经理解树形背包了。 套路化的树形背包。 递推公式长这样:f[i][j]=max(f[i][j],f[i][j-k]+f[t][k]); 注意f[i][0]应该在最后附为0,不然就相当于是取前m大了。 看代码: #include<bits/stdc++.h> using namespac 阅读全文
posted @ 2020-03-11 11:49 syzf2222 阅读(120) 评论(0) 推荐(0) 编辑