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 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...
随机推荐
- Android开发系列之Android项目的目录结构
今天开始正式学习Android开发的种种细节,首先从最基本的概念和操作学起. 首先看一下Android项目的目录结构. 这是我随便建立的一个test项目,我们重点关注一下几个方面的内容: 1.src目 ...
- 简单易用的Rest
今天碰巧,用到了淘宝的在线IP地址查询的Rest API,它提供接口给用户查询IP地址的归宿地.数据库比较庞大,准确性也比较高.地址为:http://ip.taobao.com/instruction ...
- socket 基础学习
这个示例程序是同步套接字程序,功能很简单,只是客户端发给服务器一条信息,服务器向客户端返回一条信息:这里只是一个简单的示例,是一个最基本的socket编程流程,在接下来的文章中,会依次记录套接字的同步 ...
- 没用调用flush导致的数据保存丢失
在将字符串保存到文件时,我们采有下面的写法,大部分情况下,都可以直接将数据保存到文件中, using (var fs = System.IO.File.Create(path)) { var sw = ...
- json 筛选数据 $.grep过滤数据
var data = { status: "ok", image_size_list: [ { image_size_id: "22", ad_class: & ...
- opengl雾开启
#include <GL/glut.h> #include <stdio.h> #include <iostream> using namespace std; s ...
- 图片生成操作属性导致WP内存溢出解决办法
在开发的项目中,发现经常会出现异常 “内存溢出,不能再继续执行程序”,通过搜索一些国外的文章,发现原来是由于项目中的图片比较多,而生存操作设为了“内容”.通过设置图片的生成操作为“无”,复制操作为“如 ...
- hdu 1255 覆盖的面积 (线段树处理面积覆盖问题(模板))
http://acm.hdu.edu.cn/showproblem.php?pid=1255 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others) Memo ...
- hdu 4268
set的利用: #include<cstdio> #include<set> #include<algorithm> #define maxn 100009 usi ...
- 解决Ubuntu14.04下Clementine音乐播放器不能播放wma文件的问题
参考:Ubuntu 14.04 安装深度音乐的方法 问题描述:播放wma文件时提示"GStreamer插件未安装". 解决方法:安装gstreamer-ffmpeg插件即可解决问题 ...