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 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...
随机推荐
- HaProxy+keepalived实现负载均衡
HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持 ...
- 队列(链式存储)C++模板实现
#include <iostream> using namespace std; //队列结点类 template <typename T> class QueueNode{ ...
- Swift 学习笔记1
最近在看Swift,努力在看相关的文档以及书籍,因为Swift3.0的更新,以及它开源了,所以打算写一些关于Swift的相关文章.让Swift能够更好的被我理解
- jQuery(function(){})与(function(){})(jQuery)的区别
jQuery(function(){ });/$(function(){ });全写为 $(document).ready(function(){}); 意义为在DOM加载完毕后执行了ready()方 ...
- 读书笔记-JavaScript中的全局对象
对于任何JavaScript程序,当程序开始运行时,JavaScript解释器都会初始化一个全局对象以供程序使用.这个JavaScript自身提供的全局对象的功能包括: 1.全局对象拥有一些常用的属性 ...
- RepeatedDNASequences BestTime_to_Buy_and_SellStockIV
/** * @Author: weblee * @Email: likaiweb@163.com * @Blog: http://www.cnblogs.com/lkzf/ * @Time: 2015 ...
- Java学习-数组
1.数组的是Object的直接子类,它属于“第一类对象”,但是它又与普通的java对象存在很大的不同,类名为:[I 一维数组:[I 二维数组:[[I 三维数组:[[[I 2.[代表了数组的维度,一个[ ...
- C#中如何按字节数截取字符串?
http://www.cnblogs.com/xuejie/archive/2012/12/14/2818452.html
- 代码审查工具 StyleCop 的探索
最近我们Advent Data Service (ADS) 在项目上需要按照代码规范进行代码的编写工作,以方便将来代码的阅读与维护. 但是人工检查起来容易遗漏或者格式不统一, ReSharper又是收 ...
- easyui源码翻译1.32--LinkButton(按钮)
前言 使用$.fn.linkbutton.defaults重写默认值对象.下载该插件翻译源码 按钮组件使用超链接按钮创建.它使用一个普通的<a>标签进行展示.它可以同时显示一个图标和文本, ...