acgo题库
  • 首页
  • 题库
  • 学习
  • 天梯
  • 备赛

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
  • 资讯
  • 竞赛
  • 讨论
  • 团队
  • 商城
登录
注册
题目详情提交记录(0)
  • 无

    #include<bits/stdc++.h> using namespace std; #define int long long struct node{ int d,p,l; bool operator <(const node&xyl)const{return d>xyl.d;} }a[100005]; int n,q,cnt,root[100005],g,L; struct pst{ int l,r,cost,vol; }t[100005<<5]; void add(int &cur,int lst,int l,int r,int p,int v){ cur=++cnt; t[cur]=t[lst]; t[cur].cost+=pv,t[cur].vol+=v; if(lp&&rp)return; int mid=l+r>>1; if(p<=mid)add(t[cur].l,t[lst].l,l,mid,p,v); else add(t[cur].r,t[lst].r,mid+1,r,p,v); } int query(int cur,int l,int r,int p){ if(l==r)return lp; if(t[t[cur].l].vol>=p)return query(t[cur].l,l,l+r>>1,p); else return t[t[cur].l].cost+query(t[cur].r,(l+r>>1)+1,r,p-t[t[cur].l].vol); } int read(){ int x=0,f=1,ch=getchar_unlocked(); for(;!isdigit(ch);ch=getchar_unlocked())if(ch=='-')f=-1; for(;isdigit(ch);ch=getchar_unlocked())x=(x<<3)+(x<<1)+(ch^48); return x*f; } void write(int x){ if(x<0)putchar_unlocked('-'),x=-x; if(x>=10)write(x/10); putchar_unlocked(x%10+'0'); } signed main(){ n=read(),q=read(); for(int i=1;i<=n;++i)a[i]={read(),read(),read()}; sort(a+1,a+n+1); for(int i=1;i<=n;++i)add(root[i],root[i-1],1,100005,a[i].p,a[i].l); while(q--){ g=read(),L=read(); int l=1,r=n,ans=-1,mid,k; while(l<=r){ mid=l+r>>1,k=query(root[mid],1,100005,L); if(k<=g&&t[root[mid]].vol>=L)ans=mid,r=mid-1; else l=mid+1; } write(~ans?a[ans].d:ans),putchar('\n'); } return 0; }

    userId_undefined
    我?、、
    时间刺客空间掌握者时空双修者分支·分支解题者枚举·枚举小能手贪心·贪心尝试者
    5阅读
    2回复
    2点赞
暂无数据

提交答案之后,这里将显示提交结果~

首页