题目链接 [洛谷] 题解 来做一下水题来掩饰ZJOI2019考炸的心情QwQ. 很明显可以线段树. 维护两个值,\(Lazy\)懒标记表示当前区间是否需要翻转,\(s\)表示区间还有多少灯是亮着的. 那么每一次翻转,\(s\)就变成了\(n-s\),\(n\)表示区间内所有灯的数量. 线段树维护一下就可以了. 代码 #include <bits/stdc++.h> using namespace std; const int N = 100000 + 6; int n, m; namespac…
POJ 1741. Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 34141 Accepted: 11420 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and…
传送门 要求维护每个点上出现次数最多的颜色. 对于每次修改,我们用树上差分的思想,然后线段树合并统计答案就行了. 注意颜色很大需要离散化. 代码: #include<bits/stdc++.h> #define N 100005 #define Max 100000 using namespace std; inline int read(){ int ans=0; char ch=getchar(); while(!isdigit(ch))ch=getchar(); while(isdigi…
题目传送门 Promotion Counting 题目描述 The cows have once again tried to form a startup company, failing to remember from past experience that cows make terrible managers! The cows, conveniently numbered 1 \ldots N1…N (1 \leq N \leq 100,0001≤N≤100,000), organ…
题目链接 题解 比较裸的树链剖分 好像树链剖分的题都很裸 线段树中维护一个区间最左和最右的颜色,和答案 合并判断一下中间一段就可以了 比较考验代码能力 Code #include<bits/stdc++.h> #define LL long long #define RG register using namespace std; inline int gi() { int f = 1, s = 0; char c = getchar(); while (c != '-' &&…
Code: #include<cstdio> #include<queue> #include<vector> #include<cstring> #include<algorithm> using namespace std; const int maxn=203; const int INF=100000+233; int s,t; int mapp[maxn]; struct Edge{ int from,to,cap; Edge(int…
Code: #include <cstdio> #include <algorithm> #include <string> #include <cstring> using namespace std; #define maxn 50005*256 #define ll long long int n,m,tree; struct SEGIN { int cnt; long long sumv[maxn],lazy[maxn]; int lson[maxn…