题目链接

有N次操作,每次都是将第i个数放置在第pos个数的后面,并且这个数的值是val。

这个线段树的思维确实很好,我们可以发现,后面放进去的数,一定是强制位置的,而前面放的数,会随着后面的数进入而改变位置,所以我们可以尝试着先放后面的数,再处理前面的数,最后一个数一定是放在(pos[N] + 1)这个位置上的,而再后面的数呢,如果本来是放在pos[N]前面的,可能还是在pos[N]的前面,跟什么有关呢?可以多举几组例子,不难发现,假如这个数原先要放在第pos(i)的位置后面,现在呢在pos(i)及其前面已经没有那么多的位置了,说明了这些位置被其他的人给占有了,也相对应的,它的位置也是要相对后移,因为原本在它之后的操作如果有在它之前位置上的话,也就是会让它的位置向后挪动的道理,而在它之前操作的是不影响的。

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int maxN = 2e5 + ;
int tree[maxN<<], N, pos[maxN], val[maxN], ans[maxN];
inline void pushup(int rt) { tree[rt] = tree[lsn] + tree[rsn]; }
inline void buildTree(int rt, int l, int r)
{
if(l == r) { tree[rt] = ; return; }
int mid = HalF;
buildTree(Lson);
buildTree(Rson);
pushup(rt);
}
inline void update(int rt, int l, int r, int qx, int num)
{
if(l == r)
{
tree[rt] = ;
ans[l] = num;
return;
}
int mid = HalF;
if(qx <= tree[lsn]) update(Lson, qx, num);
else update(Rson, qx - tree[lsn], num);
pushup(rt);
}
int main()
{
while(scanf("%d", &N) != EOF)
{
buildTree(, , N);
for(int i=; i<=N; i++) scanf("%d%d", &pos[i], &val[i]);
for(int i=N; i>=; i--) update(, , N, pos[i] + , val[i]);
for(int i=; i<=N; i++) printf("%d%c", ans[i], i == N ? '\n' : ' ');
}
return ;
}

最新文章

  1. 品味FastDFS~第三回 项目中的FastDFS
  2. Windows Server 2012安装时所需要的KEY
  3. iOS 通过 JSPatch 实时修复线上 bug!
  4. 【Oracle】Oracle锁表处理
  5. 《android基于andFix的热修复方案》实战篇
  6. 阻止PHP彩蛋信息泄漏 [转]
  7. IOS 设备参数
  8. hdu 1800 Flying to the Mars(简单模拟,string,字符串)
  9. [转帖]ExtJs与服务器的交互(一)
  10. dtrace-oracle-vage :吕海波
  11. python中文件类的应用
  12. android调试bug集锦 onActivityResult立即返回,并且被CANCEL
  13. bzoj 3669: [Noi2014]魔法森林 动态树
  14. &lt;frameset&gt;&lt;frame&gt;&lt;iframe&gt;网页框架
  15. QImage 与 cv::Mat 之间的相互转换
  16. R语言统计分析技术研究——岭回归技术的原理和应用
  17. 阿里云yum配置
  18. 视频外同步信号研究---fvh
  19. [java]类初始化挺有意思的题目
  20. 基于bootstrap的jQuery多级列表树插件

热门文章

  1. Codeforces 1042C (贪心+模拟)
  2. HTML替换元素,非替换元素和控制元素
  3. etc/pass命令列表
  4. 13Ajax和JQuery
  5. mysql +keeplive+drbd高可用架构(MHA基于监听端口VIP的高可用)
  6. vue2.0 &#160;之 directive指令 (自定义)
  7. POJ 2054 Color a Tree (贪心)
  8. RedisTemplate 事务处理方法 watch multi exec 的使用
  9. re模块 时间模块
  10. JS原型和原型链(3)