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

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

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

这是一场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. 在Mac OS X中搭建STM32开发环境(1)

    本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 本文方法必须好用!绝不坑爹!看了N多英文资料才搞明白的,适用于STM32F4DISCOVERY评估板,带 ...

  2. SQL索引问题

    很多文章都提到使用IN,OR会破坏索引,造成全表扫描,但实际测试却不是这样. ) 或者 ,) 以上SQL文,第一组(=,IN),第二组(=,OR,IN),每一组的两个SQL文都使用相同的执行计划,执行 ...

  3. (转载)SQL中导入图片

    SQL中导入图片 分类: 论坛精贴 2006-05-10 12:07 398人阅读 评论(0) 收藏 举报 sqlimage服务器insertlogingo 1.建立过程CREATE PROCEDUR ...

  4. python 中函数的参数

    一.python中的函数参数形式 python中函数一般有四种表现形式: 1.def function(arg1, arg2, arg3...) 这种是python中最常见的一中函数参数定义形式,函数 ...

  5. hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)

    DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...

  6. python 脚本

    mag3.py 1,import import sys from org.eclipse.jface.dialogs import MessageDialogfrom org.eclipse.core ...

  7. C# Windows Service调用IBM Lotus Notes发送邮件

    近日研究了下IBM Lotus Mail,这货果然是麻烦,由于公司策略,没有开放smtp,很多系统邮件都没有办法发送,于是入手google学习Lotus Mail,想做成Windows服务,提供wcf ...

  8. .net entity framework 泛型 更新与增加记录

    static public bool SaveOrUpdate<T>(T entity) where T: class { bool result = false; using (wech ...

  9. VS2010制作网站自定义安装程序 转

    最近在把一个网站打包成安装程序,这方面的文章网上有很多,也看了不少,但因为开发环境的不同,遇到了一些问题,便写下这篇文章记下整个流程(有很多资源都来自互联网,由于条目颇多,所以无法说明其来处,敬请谅解 ...

  10. noj [1475] Bachelor (找1的个数)

    http://ac.nbutoj.com/Problem/view.xhtml?id=1475 [1475] Bachelor 时间限制: 1000 ms 内存限制: 65535 K 问题描述 炎热的 ...