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

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

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

这是一场cf edu 然后当时做的时候想都没想就树状数组了,SB了,其实不需要

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<queue>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<vector>
  7. #include<cmath>
  8. using namespace std;
  9. typedef long long LL;
  10. const int N=3e5+;
  11. const int INF=0x3f3f3f3f;
  12. int a[N],n,m;
  13. struct pair{
  14. int x,y;
  15. bool operator<(const pair &e)const{
  16. return y<e.y;
  17. }
  18. }p[N];
  19. int mp[N];
  20. int c[N];
  21. void change(int x){
  22. for(int i=x;i<=n;i+=i&(-i))
  23. c[i]=max(c[i],x);
  24. }
  25. int query(int x){
  26. int ans=;
  27. for(int i=x;i>;i-=i&(-i))
  28. ans=max(ans,c[i]);
  29. return ans;
  30. }
  31. int main(){
  32. scanf("%d%d",&n,&m);
  33. for(int i=;i<=n;++i)
  34. scanf("%d",&a[i]),mp[a[i]]=i;
  35. for(int i=;i<=m;++i){
  36. scanf("%d%d",&p[i].x,&p[i].y);
  37. p[i].x=mp[p[i].x],p[i].y=mp[p[i].y];
  38. if(p[i].x>p[i].y)swap(p[i].x,p[i].y);
  39. }
  40. sort(p+,p++m);
  41. LL ans=;
  42. int cnt=;
  43. for(int i=;i<=n;++i){
  44. for(;cnt<=m&&p[cnt].y<=i;++cnt)
  45. change(p[cnt].x);
  46. LL l=query(i);
  47. ans+=i-l;
  48. }
  49. printf("%I64d\n",ans);
  50. return ;
  51. }

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. Android开发系列之Android项目的目录结构

    今天开始正式学习Android开发的种种细节,首先从最基本的概念和操作学起. 首先看一下Android项目的目录结构. 这是我随便建立的一个test项目,我们重点关注一下几个方面的内容: 1.src目 ...

  2. 简单易用的Rest

    今天碰巧,用到了淘宝的在线IP地址查询的Rest API,它提供接口给用户查询IP地址的归宿地.数据库比较庞大,准确性也比较高.地址为:http://ip.taobao.com/instruction ...

  3. socket 基础学习

    这个示例程序是同步套接字程序,功能很简单,只是客户端发给服务器一条信息,服务器向客户端返回一条信息:这里只是一个简单的示例,是一个最基本的socket编程流程,在接下来的文章中,会依次记录套接字的同步 ...

  4. 没用调用flush导致的数据保存丢失

    在将字符串保存到文件时,我们采有下面的写法,大部分情况下,都可以直接将数据保存到文件中, using (var fs = System.IO.File.Create(path)) { var sw = ...

  5. json 筛选数据 $.grep过滤数据

    var data = { status: "ok", image_size_list: [ { image_size_id: "22", ad_class: & ...

  6. opengl雾开启

    #include <GL/glut.h> #include <stdio.h> #include <iostream> using namespace std; s ...

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

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

  8. hdu 1255 覆盖的面积 (线段树处理面积覆盖问题(模板))

    http://acm.hdu.edu.cn/showproblem.php?pid=1255 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memo ...

  9. hdu 4268

    set的利用: #include<cstdio> #include<set> #include<algorithm> #define maxn 100009 usi ...

  10. 解决Ubuntu14.04下Clementine音乐播放器不能播放wma文件的问题

    参考:Ubuntu 14.04 安装深度音乐的方法 问题描述:播放wma文件时提示"GStreamer插件未安装". 解决方法:安装gstreamer-ffmpeg插件即可解决问题 ...