Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19725   Accepted: 9756 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue- The Lunar New Year wa…
题面传送门 本蒟蒻想练习一下并查集,所以是找并查集标签来这里的.写题解加深理解. 解决思路 自然,看到区间修改之类很容易想到线段树,但本蒟蒻线段树会写挂,所以这里就讲比较简单的并查集思路. 并查集的核心是 \(\text{find}\) 函数.\(\text{find}\) 函数的目的是找到一个节点的父亲,本题中用于快速地找到下一个点搜谁.不带权的 \(\text{find}\) 很好理解也很好写.如果父亲是本身,直接返回即可.否则去找父亲的父亲,并更新.一般这样写: int find(int…
Buy Tickets   Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year was approaching, but unluckily the Little Cat still had schedules going here and the…
题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所击败了(l<=x<=r),被击败的人立马退出游戏让你最后输出每个人是被谁击败的,最后那个胜利者没被 人击败就输出0 思路:他的每次修改的是一个区间的被击败的人,他而且只会记录第一次那个被击败的人,用线段树堕落标记的话他会记录最后一次的,所以我们倒着来修改, 然后因为那个区间里面还包含了自己,在线段…
这种题为什么要用到主席树啊..8说了,直接上代码 /* 1-n的排列,给定所有前缀的逆序对数量,要求恢复排列 首先能确定最后一个数是什么,然后倒序确定即可 开线段树找空位:如果Ai-Ai-1=k,说明pi前面有k个数比它要大,,即有i-k-1个数比它小, 那么pi排在第i-k位,线段树查询第i-k个空位,然后把这个空位填上即可 */ #include<bits/stdc++.h> using namespace std; #define maxn 50005 int n,a[maxn],ans…
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for placing the…
 Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights…
A. Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knight…
题意:有一个输入序列,每次操作要把b[i]插入到第a[i]个,在第a[i]个后面的要后移,问最后序列. n<=200000 思路:顺序来只能用splay维护 考虑倒序,对于插入到第K个位置,在线段树二分第K个0的位置,类似于主席树 将其插入后将这个位置修改为已经有数 单点修改 ..]of longint; a,b,c:..]of longint; n,i,k:longint; procedure pushup(p:longint); begin t[p]:=t[p<<]+t[p<&…
Nice boat 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4902 Description There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his pe…