/ Randle /

记录详情

Wrong Answer

/in/foo.cc: In function 'int find_num(int, int)':
/in/foo.cc:70:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 状态 耗时 内存占用
#1 Wrong Answer 4ms 2.25 MiB
#2 Wrong Answer 4ms 2.355 MiB
#3 Wrong Answer 6ms 2.375 MiB
#4 Wrong Answer 144ms 6.152 MiB
#5 Wrong Answer 136ms 4.746 MiB
#6 Wrong Answer 137ms 7.512 MiB
#7 Wrong Answer 138ms 5.391 MiB
#8 Wrong Answer 152ms 5.414 MiB
#9 Wrong Answer 123ms 5.594 MiB
#10 Wrong Answer 121ms 4.961 MiB

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define lovelive long long
int tot;
int pos[100020];
int p[100020];
map <int,int> s;
priority_queue<int,vector<int>,greater<int> > so;
struct question
{
  int num,x;
}q[100020];
struct tree
{
  int l,r,sum;
}t[400020];
void buildtree(int i,int l,int r)
{
  t[i].l=l;
  t[i].r=r;
  if(l==r)
  {
      pos[l]=i;
    return ;
  }
  int mid=(l+r)>>1;
  buildtree(i<<1,l,mid);
  buildtree(i<<1|1,mid+1,r);
}
void insert(int i,int point)
{
  t[i].sum++;
  int mid=(t[i].l+t[i].r)>>1;
  if(t[i].l==t[i].r)
    return ;
  if(point>mid)
    insert(i<<1|1,point);
  else
    insert(i<<1,point);
}
void Delete(int i,int point)
{
  t[i].sum--;
  int mid=(t[i].l+t[i].r)>>1;
  if(t[i].l==t[i].r)
    return ;
  if(point>mid)
    Delete(i<<1|1,point);
  else
    Delete(i<<1,point);
}
int find_num(int i,int x)
{
  if(t[i].l==t[i].r)
    return t[i].l;
  if(x>t[i<<1].sum)
    find_num(i<<1|1,x-t[i<<1].sum);
  else
    find_num(i<<1,x);
}
int query(int i,int l,int r)
{
  if(r<t[i].l||l>t[i].r)
    return 0;
  if(r>=t[i].r&&l<=t[i].l)
    return t[i].sum;
  return query(i<<1,l,r)+query(i<<1|1,l,r);
}
int find_rank(int x)
{
  return query(1,1,x-1)+1;
}
int find_pre(int x)
{
  int p=find_rank(x);
  return find_num(1,p-1);
}
int find_next(int x)
{
  int p=find_rank(x);
  return find_num(1,p+t[pos[x]].sum);
}
int main()
{
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
    {
      scanf("%d%d",&q[i].num,&q[i].x);
      if(q[i].num!=4) 
        so.push(q[i].x);
    }
  int point = -2e9-1;
  while(!so.empty())
  {
      if(so.top()!=point)
        ++tot;
      s[so.top()]=tot;
      p[tot]=so.top();
      point=so.top();
      so.pop();
  }  
  buildtree(1,1,tot);
  for(int i=1;i<=n;i++)
    if(q[i].num!=4)
        q[i].x=s[q[i].x];
  for(int i=1;i<=n;i++)
  {
      switch(q[i].num)
      {
        case 1:insert(1,q[i].x);break;
        case 2:Delete(1,q[i].x);break;
        case 3:cout<<find_rank(q[i].x)<<"\n";break;
        case 4:cout<<p[find_num(1,q[i].x)]<<"\n";break;
        case 5:cout<<p[find_pre(q[i].x)]<<"\n";break;
        case 6:cout<<p[find_next(q[i].x)]<<"\n";break;
    }
  }
  return 0;
}

信息

递交者
类型
递交
题目
treap模板测试(原创)
题目数据
下载
语言
C++
递交时间
2017-12-11 20:06:04
评测时间
2017-12-11 20:06:04
评测机
分数
0
总耗时
970ms
峰值内存
7.512 MiB