https://vjudge.net/problem/POJ-2828 题目意思:有n个数,进行n次操作,每次操作有两个数pos, ans.pos的意思是把ans放到第pos 位置的后面,pos后面的数就往后推一位.最后输出每个位置的ans. 思路:根据题 目可知,最后插入的位置的数才是最终不变的数,所以可以从最后的输入作第1个放入,依此类推,倒插入.在插入时也有一定的技术,首先创建一棵空线段树时,每个节点记录当前范围内有多少个空位置.在插入时,要注意,一个数放入之后那么这个位置就不用管了,那么…
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 there. Now, he ha…
http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 10478   Accepted: 5079 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a lo…
题目链接:http://poj.org/problem?id=2828 题意就是给你n个人,然后每个人按顺序插队,问你最终的顺序是怎么样的. 反过来做就很容易了,从最后一个人开始推,最后一个人位置很容易就确定了,那最后第二个人的位置也可以推(与最后一个人的位置无关)...依次就都可以确定所有的人了. 用前缀和的思想,要是这个人的位置确定了,那么就标记这个人位置的值为0,然后回溯更新,跟求逆序对个数的思想比较类似. 线段树: #include <iostream> #include <cs…
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…
Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 12930   Accepted: 6412 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…
题意  n个人排队  每一个人都有个属性值  依次输入n个pos[i]  val[i]  表示第i个人直接插到当前第pos[i]个人后面  他的属性值为val[i]  要求最后依次输出队中各个人的属性值 从头到尾看的话  队列是动态的   无法操作  可是反过来看时  pos[i]就能够表示第i个人前面有多少个空位了  然后想到了用线段树做就简单了  线段树维护相应区间还有多少个空位  每次把i放到前面刚好有pos[i]个空位的位置即可了  详细看代码 #include <cstdio> #d…
题意: 给你n次插队操作,每次两个数,pos,w,意为在pos后插入一个权值为w的数; 最后输出1~n的权值 题解: 首先可以发现,最后一次插入的位置是准确的位置 所以这个就变成了若干个子问题, 所以用线段树维护一下每个区间剩余多少位置可选 对于一个pos 如果左儿子的剩余超过当前位置,就递归进左子树 反之就相当于留出了左儿子剩余的位置,递归进右子树,当前位置变成pos-左儿子剩余位置 请注意是在后面插入 #include<cstdio> #include<algorithm> #…
题目:http://poj.org/problem?id=2828 题意:有n个人插队,给定插队的先后顺序和插在哪个位置还有每个人的val,求插队结束后队伍各位置的val. 线段树里比较简单的题目了,点的更新.. 思想是 从后向前插入,用num存储 每一段剩余的位置. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorit…
题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except the two at the ends, every village…