线段树
混子本混
这个作者很懒,什么都没留下…
展开
-
D2. Too Many Segments (hard version)
D2. Too Many Segments (hard version) (线段树维护当前点又几条线段, 贪心删除右端点最远的一条边) 代码: #include<iostream> #include<queue> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; const int N=2e5+10; struct tree { int l原创 2022-04-19 11:47:12 · 167 阅读 · 0 评论 -
2020CCPC绵阳站 J-Joy of Handcraft
2020CCPC绵阳站 J-Joy of Handcraft 链接 题意:给定n个灯泡,那个灯泡排列在电路板上,然后每个灯泡给定你一个t和x,这个灯泡会在[2kt + 1,2kt + t],k=(0,1,2…)的时间区间内发出亮度为x的光,其他时间内不发光,求从第一秒到第m秒每一秒时亮度最大的灯的亮度为多少? 思路: 线段树 + 优化, 先把灯泡从大到小排序, 从最亮的去更新线段树, 懒标记标记, 如果一段中曾经被标记过, 就不再更新, 时间段如果曾经更新过, 就不再更新 代码: #include <原创 2022-03-20 08:13:19 · 181 阅读 · 0 评论 -
Busiest Computing Nodes
A Busiest Computing Nodes 弱鸡改了好多遍改对了 线段树维护,左右端点,以及最小值 如果当前的机器时间不允许, 先询问后面, 再询问前面 代码 #include <bits/stdc++.h> using namespace std; const int N = 1e5+10; const int INF = 0x3f3f3f3f ; struct node { int l ,r; int min_time ; }tr[N*4] ; int n, k ;原创 2021-09-22 11:24:51 · 72 阅读 · 0 评论 -
D. Bash and a Tough Math Puzzle
D. Bash and a Tough Math Puzzle 链接 记录区间最大公倍数,记录需要修改几个才能是最大公倍数为x,大于1 输出no其余yes 优化,当修改值等于2时直接返回 代码 #include <bits/stdc++.h> using namespace std; const int N =5e5 +10 ; struct node { int l , r ; int g; }tr[N * 4 ] ; int res ; int n , m ; int w[N]原创 2021-09-20 16:14:54 · 61 阅读 · 0 评论 -
B. Queue
Codeforces Beta Round #75 B. Queue 链接 遇事不决线段树 记录区间最小值, 先找右树 代码 #include <bits/stdc++.h> using namespace std; const int N =1e5 +10; struct node { int l , r ; int minn ; }tr[N * 4 ] ; int n ; int all[N] ; void push_up(node &u ,node &l ,原创 2021-09-20 15:08:44 · 67 阅读 · 0 评论 -
D. The Child and Sequence
D. The Child and Sequence 链接 题意: 三个操作 1.给 l , r 求数组 l 到 r 的和 2.给 l , r, x 让数组 l 到 r 中所有元素都mod上x 3.给k , x 改变a[k] = x 线段树,维护区间最大值和区间和, 代码 #include <bits/stdc++.h> using namespace std; const int N = 1e5+10; struct node { int l , r ; long long sum原创 2021-09-19 20:34:05 · 68 阅读 · 0 评论 -
P3373 【模板】线段树 2
P3373 【模板】线段树 2 链接 注意:线段树开了(1e5 +10 )* 4 会re三个点 修改操作 void push_down(long long u) { tr[u << 1].sum=(ll)(tr[u].mul*tr[u<< 1 ].sum+((tr[u<< 1].r-tr[u<< 1].l+1)*tr[u].add)%mod)%mod; tr[u << 1 | 1 ].sum=(ll)(tr[u].mul*tr[原创 2021-09-16 16:31:30 · 65 阅读 · 0 评论 -
P3372 【模板】线段树 1
P3372 【模板】线段树 1 代码 #include <bits/stdc++.h> using namespace std; const int N = 1e5 +10; struct node { int l ,r ; long long sum ,add ; }tr[N * 4 ] ; int w[N] ; int n, q ; void push_up(int u ) { tr[u].sum = tr[u << 1 ].sum + tr[u <&l原创 2021-09-16 15:55:43 · 64 阅读 · 0 评论 -
旅馆(线段树)
[旅馆](https://www.acwing.com/problem/content/description/263/) 代码 #include <bits/stdc++.h> using namespace std; const int N = 50010; struct node { int l , r ; int d , ld , rd ; int z ; }tr[N * 4 ] ; int n ,m ; void push_up(node &u , nod原创 2021-09-16 15:52:48 · 110 阅读 · 0 评论