2 条题解

  • 2
    @ 2023-12-16 15:49:21

    题目传送门😄

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<set>
    using namespace std;
    int read(){
        int x = 0,f = 1;
        char c = getchar();
        while (c<'0'||c>'9') {
            if (c=='-') {
                f = -1;
            }
            c = getchar();
        }
        while (c>='0'&&c<='9') {
            x = x*10+c-'0';
            c = getchar();
        }
        return x*f;
    }
    multiset<int>q;
    int n,t,x,order;
    
    int main()
    {
        q.insert(-0x7fffffff);
        q.insert(0x7fffffff);
        n = read();
        while(n--)
        {
            t = read();
            x = read();
            if(t==1)
            {
                multiset<int>::iterator it=q.lower_bound(x);
    
                order=0;
    
                for(multiset<int>::iterator i=q.begin();i!=it;i++,order++);
    
                printf("%d\n",order);
            }
            else if(t==2)
            {
                order=-1;
    
                for(multiset<int>::iterator it=q.begin();it!=q.end();it++)
                {
                    order++;
                    if(order==x)
                        printf("%d\n",*it);
                }
            }
            else if(t==3)
            {
                multiset<int>::iterator it=q.lower_bound(x);
                printf("%d\n",*(--it));
            }
            else if(t==4)
            {
                printf("%d\n",*q.upper_bound(x));
            }
            else
            {
                q.insert(x);
            }
        }
        return 0;
    }
    
    
    • 2
      @ 2023-12-16 15:44:37
      #include<cstdio>
      #include<iostream>
      #include<cmath>
      #include<algorithm>
      #include<set>
      using namespace std;
      int read(){
          int x = 0,f = 1;
          char c = getchar();
          while (c<'0'||c>'9') {
              if (c=='-') {
                  f = -1;
              }
              c = getchar();
          }
          while (c>='0'&&c<='9') {
              x = x*10+c-'0';
              c = getchar();
          }
          return x*f;
      }
      multiset<int>q;
      int n,t,x,order;
      
      int main()
      {
          q.insert(-0x7fffffff);
          q.insert(0x7fffffff);
          n = read();
          while(n--)
          {
              t = read();
              x = read();
              if(t==1)
              {
                  multiset<int>::iterator it=q.lower_bound(x);
      
                  order=0;
      
                  for(multiset<int>::iterator i=q.begin();i!=it;i++,order++);
      
                  printf("%d\n",order);
              }
              else if(t==2)
              {
                  order=-1;
      
                  for(multiset<int>::iterator it=q.begin();it!=q.end();it++)
                  {
                      order++;
                      if(order==x)
                          printf("%d\n",*it);
                  }
              }
              else if(t==3)
              {
                  multiset<int>::iterator it=q.lower_bound(x);
                  printf("%d\n",*(--it));
              }
              else if(t==4)
              {
                  printf("%d\n",*q.upper_bound(x));
              }
              else
              {
                  q.insert(x);
              }
          }
          return 0;
      }
      
      • 1

      【深基16.例7】普通二叉树(简化版)

      信息

      ID
      4004
      时间
      1000ms
      内存
      512MiB
      难度
      4
      标签
      (无)
      递交数
      12
      已通过
      5
      上传者