随笔分类 -  数据结构--主席树

摘要:首先声明题意: 1~n的两个排列,a,b,在线询问两个区间[ l1,r1 ],[ l2,r2 ],求这两个区间内相同数字的数目。 解法: 我们不妨以a数列为基准,a[i]表示a的第i位对应的b中的位置。 那么就是在区间[ l1,r1 ]中查询有多少个数值在[ l2,r2 ]中。 不难想到权值线段树, 阅读全文
posted @ 2020-03-23 22:46 syzf2222 阅读(195) 评论(0) 推荐(0) 编辑
摘要:简单的可持久化。 是刚学主席树的练手好题!! #include<bits/stdc++.h> using namespace std; const int maxn=2*1e6+10; struct node{ int l,r,val; }tr[maxn]; int n,cnt,tot,root[m 阅读全文
posted @ 2020-03-17 11:39 syzf2222 阅读(162) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示