参考这篇

#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;
}

最新文章

  1. An exception occurred while acquiring a poolable resource. Will retry.
  2. spring+ibatis+多数据源
  3. 在WebApi中实现Cors访问
  4. WM_SIZE
  5. ViewPager使用 -------滑动图片
  6. 【英语】Bingo口语笔记(46) - 不可能的表达
  7. 导入导出封装的工具类 (一) 利用POI封装
  8. Linux网络管理——Linux网络命令
  9. PHP cookie禁用时session 方案
  10. 正则表达式的方法:replace,match,test(replace参数可以是回调函数)
  11. 关于熊猫认证软件IOS安装步骤教程(适用于其他软件)
  12. How to download the installation package by ZOL Downer
  13. Java对象模型规约
  14. mvc 中合并两个list集合
  15. 【转】svn冲突问题详解 SVN版本冲突解决详解
  16. P1967 货车运输
  17. Arduino IDE for ESP8266 教程(一) 局域网 网页查看数据 不控制
  18. Linux内核分析作业八
  19. idea的maven项目不知道为啥下载不下来jar包,看本地仓库只是下载了一下xml文件,没有jar包问题
  20. Eclipse添加tomcat服务器以及解决404的问题

热门文章

  1. Wolfycz的娱乐赛题解
  2. h5-20-文件操作-拖放文件
  3. rac 添加 资源
  4. find missing conjunction, why?
  5. PT2264解码心得
  6. java中的compareto方法以及LIst列表排序的详细介绍【转】
  7. Java中“==”的使用,以及“==”和equal的比较
  8. CF983A Finite or not?
  9. poj2377 Bad Cowtractors
  10. 网页尺寸scrollHeight/offsetHeight