题意:给你若干个数对,给你一个序列,保证数对中的数都在序列中

对于这个序列,询问有多少个区间,不包含这些数对

分析:然后把这些数对转化成区间,然后对于这些区间排序,然后扫一遍,记录最靠右的左端点就好

这是一场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 水题的更多相关文章

  1. Educational Codeforces Round 10 C. Foe Pairs 水题

    C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...

  2. CodeForces 652C Foe Pairs

    只要计算每个位置最多能到哪个位置,累加即可,DP从后往前预处理一下每个位置到达的最远位置. 有坑点:输入的时候如果同一个点出发的,需要保存最小值. #include<cstdio> #in ...

  3. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  4. codeforces 569B B. Inventory(水题)

    题目链接: B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces 489A SwapSort (水题)

    A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  6. Code Forces 652C Foe Pairs

    C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  7. codeforces 706A A. Beru-taxi(水题)

    题目链接: A. Beru-taxi 题意: 问那个taxi到他的时间最短,水题; AC代码: #include <iostream> #include <cstdio> #i ...

  8. codeforces 688A A. Opponents(水题)

    题目链接: A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. CodeForces 534B Covered Path (水题)

    题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...

随机推荐

  1. win7下 mysql主从配置实现

    win7下学习 mysql主从复制 一.环境: 主服务器(master):192.168.1.23 mysql版本:5.5 从服务器(slave):192.168.1.24 mysql版本:5.5   ...

  2. position:absolute,绝对定位和相对定位,JQ隐藏和显示

    需要在指定位置,用绝对定位. 如果直接写position:absolute,top:0;left:0,那就是以浏览器的左上角为参照了 现在需要在某一个指定位置用绝对定位 解决方法 在需要用绝对定位(p ...

  3. thinkphp分页实现

    以上为我对于thinkphp分页的实现效果,两种方法,一种调用公共函数中的函数方法(参考http://www.cnblogs.com/tianguook/p/4326613.html),一种是在模型中 ...

  4. PHP 向 MySql 中数据修改操作时,只对数字操作有效,非数字操作无效,怎么办?

    问题描述:   用PHP向MySql数据库中修改数据,实现增删改(数据库能正确连接) 经测试,代码只能对数字进行正常的增删改操作,非数字操作无效   但要在课程名称中输入中文,应该如果修改呢?   存 ...

  5. mysql更改默认存储引擎

    在mysql的官网上看到在mysql5.5以上的版本中已经更改了默认的存储引擎,在5.5版本以前是Myisam以后是Innodb. InnoDB as the Default MySQL Storag ...

  6. linux点滴:rsync

    rsync(remote sync)是一款远程同步工具,可以实现全量备份.增量备份.本地备份.删除,核心功能是远程数据备份. 工作原理 rsync核心算法 1.分块checksum算法 首先,把文件平 ...

  7. zoom 用法

    from: http://www.jb51.net/css/40285.html 其实Zoom属性是IE浏览器的专有属性,Firefox等浏览器不支持.它可以设置或检索对象的缩放比例.除此之外,它还有 ...

  8. uCGUI窗口操作要点

    uCGUI窗口操作要点 1. 创建一个窗口的时候,会给此窗口发送“创建(WM_CREATE)”消息,从而执行它的回调函数:如果创建窗口的标志带有“可视标志(WM_CF_SHOW)”,那么在后续执行GU ...

  9. Python之添加新元素

    现在,班里有3名同学: >>> L = ['Adam', 'Lisa', 'Bart'] 今天,班里转来一名新同学 Paul,如何把新同学添加到现有的 list 中呢? 第一个办法是 ...

  10. C# - 参数数组Params

    参数数组可以使用个数不定的参数调用函数,此时用params关键字定义它们. 限制:必须是函数定义中的最后一个参数:必须是同一类型的. 优点:不用在调用代码中传入数组,指定参数个数不受限制,可以不指定该 ...