Codeforces 240F. TorCoder 线段树】的更多相关文章

线段树统计和维护某一区间内的字母个数.. . . F. TorCoder time limit per test 3 seconds memory limit per test 256 megabytes input input.txt output output.txt A boy named Leo doesn't miss a single TorCoder contest round. On the last TorCoder round number 100666 Leo stumbl…
I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个点,初始时候每个点权值都为0,m次修改,对v的叶子节点且距离小于d的都加上x 也就是v以下d层包括v自身都加上x 问最后每个点的权值 现在一想 用线段树来维护就是很自然的事了 但是要维护什么值呢 维护的就是某个深度上增加的值 先更新 后回溯取消更新 详见代码注释 #include <cstdio>…
D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy…
Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of nn opening '(' and closing ')' brackets. A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expressio…
Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in other words, a string s* of length n, consisting of characters "(" and ")". Sereja needs to answer m queries, each of them is describe…
http://codeforces.com/problemset/problem/91/B B. Queue time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output There are n walruses standing in a queue in an airport. They are numbered startin…
Description Translated by @Nishikino_Maki from Luogu 行吧是我翻的 Mad scientist Mike has constructed a rooted tree, which consists of n n vertices. Each vertex is a reservoir which can be either empty or filled with water. The vertices of the tree are numb…
题意: 有n个点,q个询问, 每次询问有一种操作. 操作1:u→[l,r](即u到l,l+1,l+2,...,r距离均为w)的距离为w: 操作2:[l,r]→u的距离为w 操作3:u到v的距离为w 最终求起点到其他点的最短距离,到达不了输出-1 题解 线段树优化建图+最短路... 不知道这种东西,百度了一下,好像最早的是POI2015的PUS,然后2017/2018的oi也都出过, 还是要见识一下的... 顺便记录一下,封装好的djisktra和graph 代码如下: #include <bit…
题目链接:https://cn.vjudge.net/problem/CodeForces-893F 题目大意:给你n个点,每一个点有权值,然后这n个点会构成一棵树,边权为1.然后有q次询问,每一次询问包括t1和t2.让你找出以t1为根节点的树上,距离t1不超过t2的节点,最小的点权值. 每一次的t1是(上次询问的结果+t1)%n+1,t2是(上次询问的结果+t1).所以就必须的强制在线了. 具体思路:线段树合并,通过dfs序进行遍历,以每一个点的深度作为下标建树.一开始,每一个节点储存的是从当…
Souvenirs 我们将询问离线, 我们从左往右加元素, 如果当前的位置为 i ,用一棵线段树保存区间[x, i]的答案, 每次更新完, 遍历R位于 i 的询问更新答案. 我们先考虑最暴力的做法, 我们先找到位于 i 前面第一个 j, a[ j ] > a[ i ], 那么x 属于 [ 1, j ]的答案 就会被a[ j ] - [ i ] 更新一下. 然后下一个找在 j 前面第一个 k, a[ k ] >= a[ i ] && a[ k ] < a[ j ], 这个过…