luogu3960 列队
2024-10-21 11:57:33
参考这篇
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
int n, m, q, maxn, rot[300005], cnt, uu, vv;
ll ans;
vector<ll> vec[300005];
struct Node{
int l, r, sum;
}nd[11000005];
int queryPos(int o, int l, int r, int x){
if(l==r) return l;
else{
int mid=(l+r)>>1;
int siz=mid-l+1-nd[nd[o].l].sum;
if(x<=siz) return queryPos(nd[o].l, l, mid, x);
else return queryPos(nd[o].r, mid+1, r, x-siz);
}
}
void shanchu(int &o, int l, int r, int x){
if(!o) o = ++cnt;
nd[o].sum++;
if(l==r) ;
else{
int mid=(l+r)>>1;
if(x<=mid) shanchu(nd[o].l, l, mid, x);
else shanchu(nd[o].r, mid+1, r, x);
}
}
void delCol(int x){
int pos=queryPos(rot[n+1], 1, maxn, x);
shanchu(rot[n+1], 1, maxn, pos);
if(pos<=n) ans = (ll)m * pos;
else ans = vec[n+1][pos-n-1];
}
void delRow(int uu, int vv){
int pos=queryPos(rot[uu], 1, maxn, vv);
shanchu(rot[uu], 1, maxn, pos);
delCol(uu);
vec[uu].push_back(ans);
if(pos<=m-1) ans = (ll)m * (uu - 1) + pos;
else ans = vec[uu][pos-m];
}
int main(){
cin>>n>>m>>q;
maxn = max(n, m) + q;
while(q--){
scanf("%d %d", &uu, &vv);
if(vv==m) delCol(uu);
else delRow(uu, vv);
printf("%lld\n", ans);
vec[n+1].push_back(ans);
}
return 0;
}
最新文章
- An exception occurred while acquiring a poolable resource. Will retry.
- spring+ibatis+多数据源
- 在WebApi中实现Cors访问
- WM_SIZE
- ViewPager使用 -------滑动图片
- 【英语】Bingo口语笔记(46) - 不可能的表达
- 导入导出封装的工具类 (一) 利用POI封装
- Linux网络管理——Linux网络命令
- PHP cookie禁用时session 方案
- 正则表达式的方法:replace,match,test(replace参数可以是回调函数)
- 关于熊猫认证软件IOS安装步骤教程(适用于其他软件)
- How to download the installation package by ZOL Downer
- Java对象模型规约
- mvc 中合并两个list集合
- 【转】svn冲突问题详解 SVN版本冲突解决详解
- P1967 货车运输
- Arduino IDE for ESP8266 教程(一) 局域网 网页查看数据 不控制
- Linux内核分析作业八
- idea的maven项目不知道为啥下载不下来jar包,看本地仓库只是下载了一下xml文件,没有jar包问题
- Eclipse添加tomcat服务器以及解决404的问题
热门文章
- Wolfycz的娱乐赛题解
- h5-20-文件操作-拖放文件
- rac 添加 资源
- find missing conjunction, why?
- PT2264解码心得
- java中的compareto方法以及LIst列表排序的详细介绍【转】
- Java中“==”的使用,以及“==”和equal的比较
- CF983A Finite or not?
- poj2377 Bad Cowtractors
- 网页尺寸scrollHeight/offsetHeight