codeforces gym 100342F Move to Front
来源:互联网 发布:数据提供商 编辑:程序博客网 时间:2024/05/31 15:18
题意:
给一个1-N的排列,给M个询问,每次问编号为x的数在数组的第几个位置,同时把编号为x的这个数提到数组的最前面。
思路:
首先我们得知道编号为x的数前面有多少个数,这个时候就是可以用树状数组来优化了,我们记录开个数组mp记录一下编号为x的数在树状数组中的位置是多少,同时每次询问的时候直接得到它在树状数组中的位置,然后又直接求和就是可以得到答案了啊,然后就是去维护一个把数提上前的操作了,采用的是树状数组最前面预留n的空间,每次提前,原来位置update -1,新的提前的位置 update +1 , 同时更新mp数组。
0 0
- codeforces gym 100342F Move to Front
- Codeforces Gym 100342F Move to Front 平衡树
- Codeforces Gym-101617F Move Away [计算几何]
- Move-to-front transform 算法
- codeforces Gym 101102F
- Codeforces-GYM-100726F
- Codeforces GYM 100803F
- 【Codeforces Gym 100187F 】+ 贪心
- codeforces-gym-100187-F【贪心】
- Codeforces gym 101350F 想法
- Codeforces Gym 101142 F. Folding
- Codeforces Gym 101164 F. Letter
- Codeforces Gym 100379I Move the queen to the corner! 威佐夫博弈变形 + 高精度
- Codeforces Gym 100379J Move the (p, q)-knight to the corner!(DP+lucas定理)
- codeforces gym 101142 F(思维)
- Codeforces Gym 100642 C D F
- Codeforces Gym-101116-F (Flight Plan)
- Codeforces Gym 100379J Move the (p, q)-knight to the corner! 组合数学DP, Lucas定理
- 第三周周报
- cocos2dx,elipse,Errors occurred during the build,java.lang.NullPointerException打包Android错误
- Java学习--(八)多态
- Add Two Numbers
- Android开发环境的配置(Ubuntu 14.04 64位)
- codeforces gym 100342F Move to Front
- pl统计小程序a
- 浅析UIWebView编程
- 9.Python基础 面向对象的进一步拓展
- UVA 11292 Dragon of Loowater
- 李泽影的第一篇博客
- LA 5092 && hdu 3723 Delta Wave (卡特兰数)
- mac android studio NDK 安装使用(不用翻墙)
- 我只是一个卖煎饼果子的,你跟我谈个鸡毛营销战略,这么牛B自己敲钟去啊 ...