top

树链剖分学习笔记

徘徊边缘 提交于 2019-12-03 10:10:29
树链剖分 概述 :通过将一棵树上的点分为轻重链,来降低复杂度,此时lca查询复杂度为 \(O(logn)\) ,支持在线。 前置 重儿子 :一个有根树的一个点 子树最大的儿子 轻儿子 :其它的儿子 重链 :由重儿子连接成的链 轻链 :其它的所有链 下图是一棵剖好的树 图片来自于[ 知识点]树链剖分 树剖 树剖本体其实只有两个dfs 第一个dfs处理每个子树的大小,重儿子一类的信息 第二个dfs处理剖出的链的信息 void dfs1(int x) { int mx = -1; for(int i = head[x]; i; i = e[i].next) { int v = e[i].v; if(v == fa[x]) continue; dep[v] = dep[x] + 1;//处理深度 fa[v] = x;//父节点 siz[x]++;//大小 dfs1(v); siz[x] += siz[v];//回溯 if(siz[v] > mx) {//保留重儿子 mx = siz[v]; son[x] = v; } } } void dfs2(int x, int tp) { top[x] = tp;//链顶 if(son[x] != 0) { dfs2(son[x], tp);//优先搜索重儿子,让重儿子先成链 } for(int i = head[x]; i; i = e[i]

[HEOI 2014] 大工程

末鹿安然 提交于 2019-12-03 09:57:56
前几天讲了虚树,今天就来切一道虚树的题喽。 题目概述: 给你一棵树,有 \(q\) 个询问,每个询问给出 \(k\) 个点,两两连边,边的长度为其在树上的距离,求出这 \(k\) 个点连边总长度、最短的一条边以及最长的一条边。 其中 \(\sum_{i=1}^qk<=5^4\) 大体思路: 显然是道虚树的题,那就先构建棵虚树。 对于第二三两个询问,我们都可以通过一个非常简单的DP来实现,每个询问分别用两个数组求出以它为根,第一、第二(大/小)的路径的值,但是要注意这里的两个值不能都是从同一个子树中转移过来的。 关于第一个询问,我们考虑每一条边对于答案的贡献,不难发现其被加的次数为 \(siz[u]\times siz[v]\) ,那么我们把每一条边的贡献加起来即可。 具体实现 (坑爹细节) : 对于非询问点(即通过 \(LCA\) 关系而加入虚树的点),我们不妨称之为关系户。 关系户不能进入 \(siz\) 的统计(显然)。 关系户只能作为连接点,即只能以第一、第二(大/小)的路径的值相加来更新答案。(显然) 虚树的根为所有点加入完毕后,剩下的栈中的那个栈顶。(显然) 代码: #include <bits/stdc++.h> using namespace std; const int N=1e6+5,inf=1e9; int f[N][21],fir[N],sec[N],Fir

Fixed sidebar on the scroll stop at div

匿名 (未验证) 提交于 2019-12-03 09:13:36
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I try to make sure that a div "filter" becomes fixed when scrolling and then stop when it comes down to "outside_footer_wrapper". use the following script but can not get it to work? jsfiddle $(function() { var top = $('#filter').offset().top - parseFloat($('#filter').css('marginTop').replace(/auto/, 0)); var footTop = $('#outside_footer_wrapper').offset().top - parseFloat($('#outside_footer_wrapper').css('marginTop').replace(/auto/, 0)); var maxY = footTop - $('#filter').outerHeight(); $(window).scroll(function(evt) { var y = $(this)

SQL Server TOP(1) with distinct

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to extract the first row I get after ordering the result by i_version_id . If I do not use TOP(2) , my query works as expected ans returns all results sorted by i_version_id. But when I add the TOP(2) (as shown below), it says that there is a syntax error near distinct . Please let me know what I am doing wrong. SELECT TOP(2) distinct(i_version_id) FROM [PaymentGateway_2006].[dbo].[merchant] WHERE dt_updated_datetime > '2013-11-11' GROUP BY i_version_id ORDER BY i_version_id; 回答1: If you're only getting the TOP 1 then distinct is

Top layout guide is deprecated in iOS 11

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: As topLayoutGuide property is deprecated in iOS 11, What is alternative to use top layout guide ? backView.topAnchor.constraint(equalTo: topLayoutGuide.topAnchor) 回答1: TopLayoutGuide is deprecated in iOS 11 so we have option to use SafeAreaLayoutGuide like this : First we can get view safeAreaLayoutGuide let guide = view.safeAreaLayoutGuide Second add constraint to guide searchBackView.topAnchor.constraint(equalTo: guide.bottomAnchor).isActive = true 文章来源: Top layout guide is deprecated in iOS 11

数据结构--栈的学习

爷,独闯天下 提交于 2019-12-03 07:13:33
栈是应用较广的一种数据结构,分为链栈和顺序栈。 链栈的实现: #include <iostream> using namespace std; struct node { int data; node *next; }; node *top; void push(int x) { node *n=new node; n->data=x; n->next=top; top=n; } void pop() { if(top==NULL) { cout<<"no elements"<<endl; } else { node *p=top; cout<<"delete:"<<top->data<<endl; top=top->next; delete p; } } void show() { node *n=top; while(n!=NULL) { cout<<n->data<<endl; n=n->next; } } int main() { int ch, x; do { cout << "\n1. Push"; cout << "\n2. Pop"; cout << "\n3. Print"; cout << "\nEnter Your Choice : "; cin >> ch; if (ch == 1) { cout << "\nInsert : "; cin >> x;

js监听滚动到相应的div

拜拜、爱过 提交于 2019-12-03 05:30:03
<nav> <ul> <li><a href="#About">About</a></li> <li><a href="#Skill">Skill</a></li> <li><a href="#Experience">Experience</a></li> <li><a href="#More">More</a></li> <li><a href="#Contact">Contact</a></li> </ul> </nav> <div id = "About"> </div> <div id = "Skill"> </div> <div id = "AExperience"> </div> <div id = "More"> </div> <div id = "Contact"> </div> 一、点击a跳转到相应的div var a = $('a[href]', 'nav'); a.click(function(){ var href = $(this).attr('href'); var o = $(href).offset(); $(window).scrollTop(o.top, 1000); //增加个动画效果 }); 二、页面滚动时候,给上述a添加一个 ative的样式 var a = $('a[href]', 'nav'); $(window).on('scroll

Uncaught TypeError: Cannot read property 'top' of undefined

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I apologize if this question has already been answered. I've tried searching for solutions but could not find any that suited my code. I'm still new to jQuery. I have two different types of sticky menus for two different pages. Here's the code for both. $ ( document ). ready ( function () { var contentNav = $ ( '.content-nav' ). offset (). top ; var stickyNav = function () { var scrollTop = $ ( window ). scrollTop (); if ( scrollTop > contentNav ) { $ ( '.content-nav' ). addClass ( 'content-nav-sticky' ); } else {; $ ( '.content

JQ的offset().top与JS的getBoundingClientRect区别详解,JS获取元素距离视窗顶部可变距离

ε祈祈猫儿з 提交于 2019-12-03 02:38:32
壹 ❀ 引 我在 JQ的offset().top与js的offsetTop区别详解 这篇博客中详细分析了JQ方法offset().top与JS属性offsetTop的区别,并得出了一条 offset().top = offsetTop - scrollTop 的结论,不过此结论只适用于监听元素滚动条,而window的滚动条并不满足。那么在滚动window滚动条时如何获取元素距离视窗顶部的距离呢,这就不得说说本文的主角getBoundingClientRect方法。 贰 ❁ 关于getBoundingClientRect() 我们可以先拷贝下面的代码,动手起来跟着操作一遍,印象会深刻,需要引入JQ,这里提供一个 静态资源地址 ,进去搜索JQ直接复制地址引入即可: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="css/demo.css"> </head>

null character(s) ignored enabled by default

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to implement stack with array! Every time i execute the program runs fine but i am getting warning as null character(s) ignored enabled by default What does this warning mean?.. what am i doing wrong? My code is: #include<stdio.h> #include<stdlib.h> # define MAX 10 int top=-1; int arr[MAX]; void push(int item) { if(top==MAX-1) { printf("OOps stack overflow:\n"); exit(1); } top=top+1; arr[top]=item; }//warning int popStack() { if(top==0) { printf("Stack already empty:\n"); exit(1); } int x=arr[top]; top=top-1; return x; } void