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

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

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

这是一场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. head 头标签(转发)

    HTML head 头标签 paddingme | 04 Oct 2014 HTML head 头部分的标签.元素有很多,涉及到浏览器对网页的渲染,SEO 等等,而各个浏览器内核以及各个国内浏览器厂商 ...

  2. 深入理解javascript中的闭包!(转)

    1.闭包的经典错误 假如页面上有若干个div,我们想给它每个绑定一个onclick方法,于是有了下面的代码. function A(){ var divs=document.getElementsBy ...

  3. 捕获ClientDataSet.ApplyUpdates和SocketConnection异常

    核心提示:如何捕获ClientDataSet.ApplyUpdates的错误,不用ReconcileError... var cdsEmp:TClientDataSet; //保存 procedure ...

  4. opengl多重采样

    效果图如下,两幅图效果是一样的,只是换了个背景.两幅图均是左侧使用了多重采样,右侧的没有使用多重采样.

  5. 关于return和exit

    关于return和exit 在子进程退出的时候有两种方式,exit和exec族函数,不能使用return,为什么不能用return呢,exit改成return 会出现父子进程又各自重复开始进行. 1. ...

  6. Network boot from AMD Am79C970A

    用虚拟机安装winxp系统,出现错误信息如下: Network boot from AMD Am79C970A Copright (c)2003-2005 Vmware, Inc. Copright ...

  7. spring ioc aop 原理

    spring ioc aop 原理 spring ioc aop 的原理 spring的IoC容器是spring的核心,spring AOP是spring框架的重要组成部分. 在传统的程序设计中,当调 ...

  8. <二> ASP.NET AutoPostBack

    当把Web控件的AutoPostBack属性设置为True时,自动回送功能被开启,ASP.NET使用客户端的 JavaScript来连接客户端和服务器端的代码.创建一个Web控件属性包含AutoPos ...

  9. windows store app search contract

    代码如下: html: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...

  10. 图片生成操作属性导致WP内存溢出解决办法

    在开发的项目中,发现经常会出现异常 “内存溢出,不能再继续执行程序”,通过搜索一些国外的文章,发现原来是由于项目中的图片比较多,而生存操作设为了“内容”.通过设置图片的生成操作为“无”,复制操作为“如 ...