当前位置:网站首页>[8.3] Code Source - [meow ~ meow ~ meow~] [tree] [and]
[8.3] Code Source - [meow ~ meow ~ meow~] [tree] [and]
2022-08-05 04:01:00 【ZhgDgE】
#865. 喵 ~ 喵 ~ 喵~
题意:有 m ( 1 ≤ m ≤ 1 0 5 ) m(1\leq m\leq 10^5) m(1≤m≤105) 次操作,每次操作:如果 o p = 1 op=1 op=1 ,Is added in the weight set is an interval [ l , r ] ( 1 ≤ l ≤ r ≤ 1 0 5 ) [l,r](1\leq l\leq r\leq 10^5) [l,r](1≤l≤r≤105) ;如果 o p = 2 op=2 op=2 ,Is given a range [ l , r ] ( 1 ≤ l ≤ r ≤ 1 0 5 ) [l,r](1\leq l\leq r\leq 10^5) [l,r](1≤l≤r≤105) ,How many q collection and a given interval intersect.
思路:This problem has a more classic solution.假设当前有 m m m 个区间 ,给定区间 [ L , R ] [L,R] [L,R] ,The fellowship with the given interval of the interval number is :左端点在 R R R On the left side of the interval number 减去 右端点在 L L L On the left side of the interval number,即 ∑ i = 1 m [ l i ≤ R ] − ∑ i = 1 m [ r i < L ] \sum_{i=1}^m[l_i\leq R]-\sum_{i=1}^m[r_i<L] ∑i=1m[li≤R]−∑i=1m[ri<L] .Because the left endpoint in R R R 左边的区间,If you don't intersect with the given interval,Is necessarily right endpoints in L L L 左边.
Then how is open two tree array,一个维护 { l } \{l\} { l} 一个维护 { r } \{r\} { r} ,就可以了.
AC代码:http://oj.daimayuan.top/submission/317153
#154. 树
题意:有一棵 n ( 1 ≤ n ≤ 3000 ) n(1\leq n\leq 3000) n(1≤n≤3000) 个节点的以 1 1 1 为根的有根树.现在可以对这棵树进行若干次操作,每一次操作可以选择树上的一个点然后删掉这个点和它的儿子之间的所有边.
现在想要知道对于每一个 k ∈ [ 1 , n ] k∈[1,n] k∈[1,n] ,最少需要多少次操作才能让图中恰好存在 k k k 个联通块.
思路:Initial connecting piece number for 1 1 1 ,定义 s i z ( i ) siz(i) siz(i) 表示点 i i i How many sons,如果删去 i i i Son to the side of the connecting block number will increase s i z ( i ) siz(i) siz(i) .
那么问题就转化成了 01 背包问题:背包体积上限为 k ( k ∈ [ 1 , n ] ) k(k\in[1,n]) k(k∈[1,n]) ,每个物品只有一个,体积为 s i z ( i ) siz(i) siz(i) ,价值为 1 1 1 ,Asked to fill a backpack k k k A volume of the minimum value.
AC代码:http://oj.daimayuan.top/submission/317187
#155. 与
题意:给定 n , k ( 1 ≤ n , k ≤ 1 0 4 ) n,k(1\leq n, k\leq 10^4) n,k(1≤n,k≤104) .Calculate how many length of k k k 的数组 a 1 , a 2 , ⋯ , a k a_1,a_2,\cdots,a_k a1,a2,⋯,ak ,满足:
- ∑ i = 1 k a i = n , a i ≥ 0 ∑_{i=1}^ka_i=n,a_i≥0 ∑i=1kai=n,ai≥0 .
- 对于任意的 i = 1 , … , k − 1 i=1,…,k−1 i=1,…,k−1 有 a i AND a i + 1 = a i + 1 a_i ~\text{AND} ~a_{i+1}=a_{i+1} ai AND ai+1=ai+1 .其中 AND \text{AND} AND 是与操作.
输出答案对 1 0 9 + 7 10^9+7 109+7 取模的结果.
思路:Consider the binary on every,从 1 ∼ k 1\sim k 1∼k 必然是 1 , 1 , ⋯ , 1 , 0 , ⋯ , 0 , 0 1,1,\cdots,1,0,\cdots,0,0 1,1,⋯,1,0,⋯,0,0 ,That we defined from the perspective of binary,This state the number of less,Move faster.定义 d p ( b i t , j ) dp(bit,j) dp(bit,j) 表示前 0 ∼ b i t 0\sim bit 0∼bit These bits can be as 0 / 1 0/1 0/1 ,且 b i t ∼ inf bit\sim \inf bit∼inf 位上都为 0 0 0 ,且总和为 j j j 时的方案数 .那么我们枚举 b i t bit bit How many letters are there in the seat 1 1 1 ,转移方程就是 d p ( b i t , j ) = ∑ j − k × 2 b i t ≥ 0 d p ( b i t − 1 , j − k × 2 b i t ) dp(bit,j)=\sum_{j-k\times 2^{bit} \geq 0}dp(bit-1,j - k\times 2^{bit}) dp(bit,j)=∑j−k×2bit≥0dp(bit−1,j−k×2bit)
边栏推荐
猜你喜欢

This year's Qixi Festival, "love vegetables" are more loving than gifts
![[BJDCTF2020]EasySearch](/img/60/464de3bcdda876171b9f61ad31bff1.png)
[BJDCTF2020]EasySearch

shell脚本:for循环与while循环

Industry Status?Why do Internet companies prefer to spend 20k to recruit people rather than raise their salary to retain old employees~

Some conventional routines of program development (1)
![[Paper Notes] MapReduce: Simplified Data Processing on Large Clusters](/img/89/8adef42b0cfd154e6fa7205afaeade.png)
[Paper Notes] MapReduce: Simplified Data Processing on Large Clusters

UE4 第一人称角色模板 添加生命值和调试伤害
![[CISCN2019 华东南赛区]Web11](/img/15/843334fec0a5cc8cfaba92aab938db.png)
[CISCN2019 华东南赛区]Web11

UE4 第一人称角色模板 添加冲刺(加速)功能

Use Unity to publish APP to Hololens2 without pit tutorial
随机推荐
Mysql的undo log详解
The most effective seven performance testing techniques of software testing techniques
程序开发的一些常规套路(一)
包拉链不可用,但是是被另一个包。
Developing Hololens encountered The type or namespace name 'HandMeshVertex' could not be found..
【8.2】代码源 - 【货币系统】【硬币】【新年的问题(数据加强版)】【三段式】
Defect detection (image processing part)
Index Mysql in order to optimize paper 02 】 【 10 kinds of circumstances and the principle of failure
Initial solution of the structure
Redis key basic commands
2022 Hangzhou Electric Multi-School 1st Game
Use CH341A to program external Flash (W25Q16JV)
UE4 为子弹蓝图添加声音和粒子效果
Redis1:Redis介绍、Redis基本特性、关系型数据库、非关系型数据库、数据库发展阶段
DNS被劫持如何处理?
UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)
What is the difference between SAP ERP and ORACLE ERP?
Mathematics - Properties of Summation Symbols
七夕节代码表白
【测量学】速成汇总——摘录高数帮