poj2828】的更多相关文章

题意:有一个输入序列,每次操作要把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<&…
[poj2828]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…
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…
Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 17326   Accepted: 8601 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…
题目链接:https://vjudge.net/problem/POJ-2828 题意:有n个人,依次给出这n个人进入队列时前面有多少人p[i],和它的权值v[i],求最终队列的权值序列. 思路:基本类似于poj2182,简化题意后即为求序列1..n中第k小的值的问题.读入数据量比较大,最好读入优化.我们从n..1逆序遍历,则可以确认最后一个人的最终位置为p[n]+1,然后从序列中删除p[n]+1,继续操作倒数第二个...这一操作可以通过线段树来完成.线段树的结点包括3个值:l(区间左端点),r…
poj2182题意:有一个1~n的排列,现在给定每个人前面有多少个人的编号比他大,求这个排列是什么.n<=8000 poj2182题解: 逆序做,可以确定二分最后一个是什么,然后删除这个数.树状数组维护每个数前面有多少个数比它小. poj2828题意:有 n 个人排队买票,他们依次到来,第 i 个人来的时候会站在第pos[i]个人后面,并且他的编号为v[i].求最后的队列中每个位置人的编号. poj2828题解: 来一个例子模拟: 0 (3) //编号为3的人插入第0个人后面 1 (2) 1 (…
题目链接: https://cn.vjudge.net/problem/POJ-2828 题目大意: 插队的问题,每个案例给出n,代表有n个插队的,每个给出p,v,意思是代号为v的人插在了第p个人的后面,问最后的队伍的排列? 解题思路: 如果从前往后递推,每次插入在前面的话,后面的人都需要往后移动,所以考虑从后往前放 从后往前退的话每次可以推到确定的位置,插入在位置为i的地方,说明按从前往后放的时候前面有i个人,从后往前放的话就是前面有i个空格,放在第i+1个空格的地方,这样逆序放的话每次都可以…
[POJ2828] Buy Tickets(待续) 题目大意:多组测试,每组给出\(n\)条信息\((a,b)\),表示\(b\)前面有\(a\)个人,顺序靠后的信息优先级高 Solution.1 由后向前看,每个遇到的都是确定位置的,最后的人选定的位置不会改变,同样因为是倒叙输入,在第\(i\)个人后插队,也就是说他的前面一定要留下\(i\)个空格. 形象一点就是这样: 从后往前,去查找第一个大于所需要空白的位置.用线段树维护空格数目即可 Code.1 #include <iostream>…
Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19012   Accepted: 9442 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…
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…