zoukankan      html  css  js  c++  java
  • 1613. For Fans of Statistics(STL)

    1613

    高端的东西

    lower_bounder

    函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置。如果所有元素都小于val,则返回last的位置,且last的位置是越界的

    然后用map 把数映射成容器 可以简单查询到每个数出现的最前和最后位置 再与给出的L,R相比较

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<vector>
     7 #include<map>
     8 using namespace std;
     9 #define N 70010
    10 map<int,vector<int> >t;
    11 vector<int>::iterator it;
    12 int main()
    13 {
    14     int i,k,n,a;
    15     scanf("%d",&n);
    16     for(i = 1; i <= n ; i++)
    17     {
    18         scanf("%d",&a);
    19         t[a].push_back(i);
    20     }
    21     scanf("%d",&k);
    22     for(i = 1; i <= k ;i++)
    23     {
    24         int l,r,x;
    25         scanf("%d%d%d",&l,&r,&x);
    26         it = lower_bound(t[x].begin(),t[x].end(),l);
    27         if(it==t[x].end())
    28         printf("0");
    29         else if((*it)<=r)
    30         printf("1");
    31         else
    32         printf("0");
    33     }
    34     puts("");
    35     return 0;
    36 }
    View Code
  • 相关阅读:
    Cmake Make makefile GNU autotools
    第三方库的安装:Pangolin
    ./configure, make, sudo make install 的含义
    [Eigen]C++开源线代库
    术语解释
    KDevelop使用笔记【中文教程】
    Python-Day1
    找不到或无法加载主类
    仅仅测试Word2016发布博客
    First Day!
  • 原文地址:https://www.cnblogs.com/shangyu/p/3337031.html
Copyright © 2011-2022 走看看