Codeforces Round #169 (Div. 2)补题记录
前三题没什么可说的
CF - 276C.Little Girl and Maximum Sum
记录每个索引询问的次数,将数组内的数从大到小排序,询问次数从大到小排序,相乘求和即可。
CF - 276D.Little Girl and Maximum XOR
求区间内两个数异或的最大值。
我们考虑和异或所得的数,我们的答案就是从这个数的最高位开始,后面所有位全部置为。
注意
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#else
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
#endif
using namespace std;
#define inf __INT_MAX__
#define enf INT_MIN
#define INF LLONG_MAX
#define ENF LLONG_MIN
const int MAXN = 2e5 + 10;
const double pi = acos(-1.0);
const double eps = 1e-6;
typedef long long ll;
typedef unsigned long long ull;
#define zhengfu(x) ((x > eps) - (x < -eps))
int main() {
ll l, r;
cin >> l >> r;
if (l == r)
cout << 0 << endl;
else {
ll tmp = l ^ r;
for (ll i = 63; i >= 0; i--)
if (tmp & (1LL << i)) {
cout << (1LL << (i + 1)) - 1LL << endl;
break;
}
}
}
CF - 276E.Little Girl and Problem on Trees
给你一棵树,其中,除了根节点以外,其他的节点度数不大于2。
也就是说,如果把从中删除,那么就会变成一条条链。
两个操作,一个操作是对于节点,令与其距离不超过的节点加,包括自己。
另一个是询问节点上的加和是多少。
考虑题面:
区间更新,单点查询显然线段树树状数组
考虑区间更新:
-
当距离只局限于节点所在的链上,即不包括根节点时
只需要对于该链的节点进行简单的区间更新即可。
-
当距离不局限于所在链时,显然,更新包括了根节点
-
那么, 我们可以根据树的深度建一个树状数组,我们只需要更新之间的节点即可
-
所以,我们的更新过程就成了这样:
- 首先在链上局部更新新,范围是
- 然后在深度树状数组更新,范围是
- 然后在链上局部更新,范围是
-
再考虑单点查询,答案显然就变成了,深度树状数组链上树状数组的和。
#if __cplusplus >= 201103L
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#else
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <string.h>
#include <vector>
#endif
using namespace std;
#define inf __INT_MAX__
#define enf INT_MIN
#define INF LLONG_MAX
#define ENF LLONG_MIN
const int MAXN = 2e5 + 10;
const double pi = acos(-1.0);
const double eps = 1e-6;
typedef long long ll;
typedef unsigned long long ull;
#define zhengfu(x) ((x > eps) - (x < -eps))
/*
每条链一个树状数组,记录链上不过根的更新
一个总树状数组记录过根的深度的更新
*/
vector<int> e[MAXN];
struct node {
vector<int> nd;
int n;
void init() {
n = nd.size() - 1;
}
inline int lowbit(int x) //核心操作,取x这个数的二进制最后一位1
{
return -x & x;
}
inline void update(int x, int k) //单点修改
{
for (; x <= n; x += lowbit(x))
nd[x] += k;
}
void update(int l, int r, int k) { //区间更新
update(l, k);
if (r < n)
update(r + 1, -k);
}
inline int query(int x) //求x的前缀和
{
int sum(0);
for (; x > 0; x -= lowbit(x))
sum += nd[x];
return sum;
}
} tree[MAXN];
int depmax = enf;
int dp[MAXN];
int nm[MAXN];
void dfs(int anc, int x, int dep, int num) {
tree[num].nd.push_back(0);
dp[x] = dep, nm[x] = num;
if (e[x].size() == 1) {
depmax = max(dep, depmax);
tree[num].init();
return;
}
for (auto it : e[x])
if (it != anc)
dfs(x, it, dep + 1, num);
}
int main() {
int n, q;
cin >> n >> q;
for (int i = 1, x, y; i < n; i++) {
cin >> x >> y;
e[x].push_back(y);
e[y].push_back(x);
}
for (int i = 1; i <= e[1].size(); i++) {
tree[i + 1].nd.push_back(0);
tree[i + 1].nd.push_back(0);
dfs(1, e[1][i - 1], 2, i + 1);
}
dp[1] = nm[1] = 1;
for (int i = 0; i <= depmax; i++)
tree[1].nd.push_back(0);
tree[1].init();
for (int i = 1, j, v, x, d; i <= q; i++) {
cin >> j >> v;
int pos = dp[v], tmp = nm[v];
if (!j) {
scanf("%d%d", &x, &d);
tree[tmp].update(max(2, pos - d), pos + d, x);
if (pos - d < 2) {
int len = d - pos + 2;
tree[tmp].update(2, len, -x);
tree[1].update(1, len, x);
}
} else {
if (v == 1)
cout << tree[1].query(pos) << endl;
else
cout << tree[tmp].query(pos) + tree[1].query(pos) << endl;
}
}
}
六花保佑代码不
/**
爆ぜろリアル!弾けろシナプス!パニッシュメント・ディス・ワールド!
';!!!:`
.;%%%%$$$$%%%;.
.;$%;. :%;.
`||` :!.
.!: ::
:; .`.
'` ..
`` .
.. ..
..
`;||!:';|%$$$%%%$$%|;'.
'|%%%%%%%%%%%%%%%%%%%%%%%%%%%%|:.
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$|:
.:!%%%%%%%%%%|!|%%%%$$&$$$%%%%%%%%%%%%%%%%|' `:'.
'!|%%%%%||%%%%%%%%%%%$&&&$%%%%%$$$%%%%%%%%%%%|'':':'.
`|%%%%%%%%%%%%%$%%%%%%%$&&&&$$%%%$$$%%%%%%%%%%%%|;:::'::':`
:%%%%%%$$%%%$$%%$%%%%%%%$&&&&&$$%%|%$%%%|!|%%%%%$!'::::;|!:'.
.;$%%%%%$$%%%$$%%$%%%%%%%%$&&&&&$$$%%$$$%%%!!%$%%%%!::!%%%%|;'.
.;%$%%%$$$%%%$$%%||%$$%%%%$$&&&&&&$$%%$$%%%%%%%$&&&$%$$$$%%%%|:.
;%%%%%$$$%%$&$%%!:!$$$%%%%$&$||&&&&$$%$$$%%%%%%$$$%%%%$$$$%%%|'
:%%$%%$$$$%$&&$%!`'|$&$%%%%$&|`.!&&&&$%$$$%%%%%%%$%%%%%%$$$$%%%;
`!%|%%%$&$%%$&$$|'.'|&&$%%%%$%|!'.:$&&&$$$$%%%%%%%%%%%%%%$$$$%%%|`
;%':%%$&&$%$&|!|'.`:|&&$%%%$$|'''``'%&&&$$$%%%%%%%%%%%%%%$&&$%%%%:
`;' ;%%$&$%%$%;;: .:!%$%%%$|` .. .!&&&$$$%%$%%%$%$$%$$%$&$%%%$;
'' .!%$&&$$%$;`:' `!%%%%:.... ....:$&$$$%$$%%$$$$$%$$%$&$%%%%;
.. .;%$&&&$%|:. ...;%|'..........'|$%%%$$%%$$&&$%$$%%%$%%%$;
;$$&&&$%!` .`....'`.... ......`!%%%$$%%$&&&$$&&$!!$%%%$:
'%$&&&&$!`. .`........``.......`!%%$$$%$&&&&$$&&$;;$%%%%'
'|$&&&&!``..```. ........`|@@|'....`:|%%$$%%$&&&&$$&&$':$%%%|`
`|$&&&&$' .``````'''::`..........``.:%%$&$%|'`!&&$$&&%':%%%%;.
;$$&&|;!:`........... .':`....`````!%$&&$%|;';&&&%|%%';%%%%:
'%$&$: ...................`''`...`:%%$&$$!`..!&&&$;`:;|%%%!`
;$&&%:..................... .':``!%$&&$;...:$&%'`;' ;%%%%:
.;$&&&$:..........`'............`!%$&&&;..'%&&! `!%%%:
.':|&&&|''`.............. ...'|$&&$||$&&&|` :|'``
.!%: `|$%|!:'`.........`:!%$&&&&&$;''. `.
.:!%$%||||||%%$$$$$$$$$%$%%$$$%%:.
`!%$%%%%%%%|||||||||||%|||||||%%%%%$%%%%|:
'%%%%%%%%%%%%||||||||!!|||||||||||%$$%%%%%%%%$%:
:%$$$%%%$%$$%||||||||!;%%||||||||%%%%%%%%%%%%%%%%|'
.;$%%%%$$$$$%%|||||%$$$$$%||||||||%$$%%%%%%%%%%%%%%'
.!%%%%%%$$%%$%%|||||;;%||||||||%$$&&|!%$$%%%$$$$$%;.
.!%%%%%%%%%%%%%%$%||%%%%%%%%%%%$&$$;`;%%%%%%%%$$!.
:%%%%%%%%%%%%%%||%%%%%%%%%%%$$$%%%%%%%%%%%%%|'
:%%%%%%%%%%$$%%%%%%%%%%%%%%%;`;%%%%%%%|:
.;%%%%%%%%%%%%%%%%%%%%%%%%%%%:..:|%%%!.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|;:`
;$%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%'
`|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;
.:!%$%%%%%%%%%%%%%%%%%%%%%%%%%%%%$!.
;!';%%%%%%%%%%%%%%%%%%%%%!:`. `|$%'
.;%%%%%%%%%%%||%%%%%%%%%|:';|%$%%%%%;.
.!%%%%%%%%%%%%$$%%%%%%%%%%%%%%%%%%%%%'
.!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$;.
.;%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%'
;%$$%%%%%%%%$$$$%%%%%%%%%%%%%%%%%%%%%'
`|$&$%%%%%%$%$$$%%%%%%%%%%%%$%%%%%$&%%!`
:%$&$%%||%%%%$$%%%$%%%%%$$!:|%||%%$&$%%!`
**/
标签:
CodeForces
, QLUACM日常训练
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· 一个基于 .NET 开源免费的异地组网和内网穿透工具
· 《HelloGitHub》第 108 期
· Windows桌面应用自动更新解决方案SharpUpdater5发布
· 我的家庭实验室服务器集群硬件清单