摘要:
思路:用Sum[dep][i]记录从tree[po].l到i中进入左子树的和。#include#include#include#include#include#include#define Maxn 100010#define inf 0x7fffffff#define lowbit(x) (x&(-x))#define lson(x) (x>1)using namespace std;struct Tree{ int l,r;}tree[Maxn*4];__int64 Sum[20][Maxn],sum[Maxn];__int64 lnum,lsum;int sorted[Ma 阅读全文
摘要:
思路:二分枚举区间第k大。用划分树查找是否符合要求的高度。#include#include#include#include#include#define Maxn 100010#define lson(x) x>1)using namespace std;int val[20][Maxn],toLeft[20][Maxn],sorted[Maxn];struct Tree{ int l,r;}tree[Maxn*4];void BuildTree(int l,int r,int dep,int po){ tree[po].l=l,tree[po].r=r; if(l==r) ... 阅读全文
摘要:
思路:直接搜索#include#include#include#includeusing namespace std;int belong[5010],num[5010],n;int dfs(int s,int pre,int cur){ int i,j; if(cur==n/2) return 1; for(i=s;ipre) { belong[j]=1; if(dfs(s+1,j,cur+1)) return 1; ... 阅读全文