LUOGU P3960 列队 (noip2017 day2T3)
2024-10-06 14:50:02
解题思路
记得当时考试我还是个孩子,啥也不会QAQ。现在回头写,用动态开点的线段树,在每行和最后一列开线段树,然后对于每次询问,把x行y列的删去,然后再把x行m列的元素加入x行这个线段树,然后再把删去元素加到最后一列里,用一个vector维护变化后的标号。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<vector> using namespace std;
const int MAXN = ;
typedef long long LL; inline int rd(){
int x=,f=;char ch=getchar();
while(!isdigit(ch)) {f=ch=='-'?:;ch=getchar();}
while(isdigit(ch)) {x=(x<<)+(x<<)+ch-'';ch=getchar();}
return f?x:-x;
} vector<LL> g[MAXN];
int n,m,q,Max,num,rt[MAXN];
LL pos;
int sum[MAXN<<],ls[MAXN<<],rs[MAXN<<]; LL query(int x,int l,int r,int k){
if(l==r) return l;
int mid=l+r>>,sizl=mid-l+-sum[ls[x]];
if(sizl>=k) return query(ls[x],l,mid,k);
else return query(rs[x],mid+,r,k-sizl);
} void modify(int &x,int l,int r){
if(!x){
x=++num;
ls[x]=rs[x]=;
}
sum[x]++;
if(l<r){
int mid=l+r>>;
if(mid>=pos) modify(ls[x],l,mid);
else modify(rs[x],mid+,r);
}
} LL Del_r(int x,LL now){
pos=query(rt[n+],,Max,x);
modify(rt[n+],,Max);
LL ret=pos<=n?1ll*pos*m:g[n+][pos-n-];
g[n+].push_back(now?now:ret);
return ret;
} LL Del_l(int x,int y){
pos=query(rt[x],,Max,y);modify(rt[x],,Max);
LL ret=pos<m?1ll*(x-)*m+pos:g[x][pos-m];
g[x].push_back(Del_r(x,ret));
return ret;
} int main(){
n=rd(),m=rd(),q=rd();Max=max(n,m)+q;
int x,y;
while(q--){
x=rd(),y=rd();
if(y==m) printf("%lld\n",Del_r(x,));
else printf("%lld\n",Del_l(x,y));
}
return ;
}
最新文章
- .Net语言 APP开发平台——Smobiler学习日志:Poplist控件的正确打开方式以及如何快速实现
- 如何判断exe或dll的目标平台及是否是.NET?
- CSS--结构和层叠
- 802.11协议帧格式、Wi-Fi连接交互过程、无线破解入门研究
- loadrunner中定义数组
- 关于iis站点无法读取 服务器共享目录的问题
- noaman日志第一条:2015-1024;“Hello.World”
- CAP原则(CAP定理)
- symbol(s) not found for architecture x86_64
- [MODx] 6. Cache &#39;!&#39; with login package
- winform/wpf 程序部署
- JS 继承(类式 与 原型式)
- EventEmitter事件处理器中的this问题
- hdu4276 依赖背包
- 字定义JSON序列化支持datetime格式序列化
- 基于报错的SQL注入整理
- algebraically closed field 代数闭域
- Subordinates CodeForces - 737C (树,构造)
- Linux -- 基于zookeeper的java api(一)
- chandy-lamport 分布式一致性快照 算法详细介绍
热门文章
- 揭秘 Flink 1.9 新架构,Blink Planner 你会用了吗?
- (转)第05节:Fabric.js的动画设置
- SGI STL rope
- System.Drawing.Imaging.ImageFormat.cs
- PAT甲级——A1108 Finding Average【20】
- 7_3.springboot2.x启动配置原理_3.事件监听机制
- USACO 2008 November Gold Cheering up the Cows /// MST oj24381
- (转)行为树(Behavior Tree)实践(1)– 基本概念
- mac brew 安装 php 环境
- 算法系列:Shell 排序