codeforces 652C Foe Pairs 水题
题意:给你若干个数对,给你一个序列,保证数对中的数都在序列中
对于这个序列,询问有多少个区间,不包含这些数对
分析:然后把这些数对转化成区间,然后对于这些区间排序,然后扫一遍,记录最靠右的左端点就好
这是一场cf edu 然后当时做的时候想都没想就树状数组了,SB了,其实不需要
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
const int N=3e5+;
const int INF=0x3f3f3f3f;
int a[N],n,m;
struct pair{
int x,y;
bool operator<(const pair &e)const{
return y<e.y;
}
}p[N];
int mp[N];
int c[N];
void change(int x){
for(int i=x;i<=n;i+=i&(-i))
c[i]=max(c[i],x);
}
int query(int x){
int ans=;
for(int i=x;i>;i-=i&(-i))
ans=max(ans,c[i]);
return ans;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i)
scanf("%d",&a[i]),mp[a[i]]=i;
for(int i=;i<=m;++i){
scanf("%d%d",&p[i].x,&p[i].y);
p[i].x=mp[p[i].x],p[i].y=mp[p[i].y];
if(p[i].x>p[i].y)swap(p[i].x,p[i].y);
}
sort(p+,p++m);
LL ans=;
int cnt=;
for(int i=;i<=n;++i){
for(;cnt<=m&&p[cnt].y<=i;++cnt)
change(p[cnt].x);
LL l=query(i);
ans+=i-l;
}
printf("%I64d\n",ans);
return ;
}
codeforces 652C Foe Pairs 水题的更多相关文章
- Educational Codeforces Round 10 C. Foe Pairs 水题
C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...
- CodeForces 652C Foe Pairs
只要计算每个位置最多能到哪个位置,累加即可,DP从后往前预处理一下每个位置到达的最远位置. 有坑点:输入的时候如果同一个点出发的,需要保存最小值. #include<cstdio> #in ...
- Codeforces Gym 100531G Grave 水题
Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...
- codeforces 569B B. Inventory(水题)
题目链接: B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 489A SwapSort (水题)
A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Code Forces 652C Foe Pairs
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- codeforces 706A A. Beru-taxi(水题)
题目链接: A. Beru-taxi 题意: 问那个taxi到他的时间最短,水题; AC代码: #include <iostream> #include <cstdio> #i ...
- codeforces 688A A. Opponents(水题)
题目链接: A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces 534B Covered Path (水题)
题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...
随机推荐
- 纯javascript 回到 顶部 实例
很多网站都会采用瀑布式的加载模式,像qq空间加载好友动态,为了用户体验更好,很多网站会加上回到顶部的连接,但大多数网站都是一下子就回到了顶部,当然,这样有这样的好处,但是我是个比较喜欢很炫的东西的人, ...
- 判断浏览器是否支持某个css3属性的javascript方法
判断浏览器是否支持css3某个属性的方法: /** * 判断浏览器是否支持某一个CSS3属性 * @param {String} 属性名称 * @return {Boolean} true/false ...
- 利用jquery的imgAreaSelect插件实现图片裁剪示例
http://www.cnblogs.com/mizzle/archive/2011/10/13/2209891.html 将用户上传的图片进行裁剪再保存是现在web2.0应用中常常处理的工作,现在借 ...
- splay学习笔记
伸展树(Splay Tree),也叫分裂树,是一种二叉排序树,它能在O(log n)内完成插入.查找和删除操作.(来自百科) 伸展树的操作主要是 –rotate(x) 将x旋转到x的父亲的位置 voi ...
- 【单片机通信协议】CAN总线基础知识
CAN总线基础知识(一) 1.1 CAN总线是什么? CAN(Controller Area Network)是ISO国际标准化的串行通信协议.广泛应用于汽车.船舶等.具有已经被大家认可的高性能和可靠 ...
- Bootstrap简易使用指南
1.框架 1.1全局样式 使用HTML5的doctype,scaffolding.less中定义全局样式,从2开始使用normalize.css,并使用reset.less进行简化 1.2默认栅格系统 ...
- AMH4.2免费版手动编译升级Nginx1.8版本方法
从AMH免费版本停留在4.2版本之后就没有进行更新和升级,而且官方提供的解决文档也比较少,毕竟免费且没有盈利的产品还是没有多少兴趣的.但是,对于大部分网站环境来说,安装和使用AMH4.2免费版本还是够 ...
- vim 分屏 screen
上下分割,并打开一个新的文件. :sp filename 左右分割当前打开的文件. Ctrl+W v 左右分割,并打开一个新的文件. :vsp filename 移动光标 Vi中的光标键是h, j, ...
- [转载]C#.NET中Dns类的常用方法及说明
IP是一种普遍应用于因特网.允许不同主机能够相互找到对方的寻址协议.IP地址由4个十进制的数字号码所组成,而每一个号码的值介于0~255之间,它虽然解决了网络上计算机的识别问题,但是IP地址确不容易记 ...
- Ubuntu下将Sublime Text设置为默认编辑器
转自将Sublime Text 2设置为默认编辑器 修改defaults.list 编辑/etc/gnome/default.list文件,将其中的所有gedit.desktop替换为sublime_ ...