操作无论是U还是L,都会使原图形分裂成两个图形,且两个图形的操作互不影响

我们又发现由于操作点只可能在下斜线上,如果将操作按x排序

那么无论是U还是L,都会将操作序列完整分割成两半,且两个操作序列互不影响

这样我们就可以对操作进行分治,每次找到最靠前的操作,并将操作序列分割

对于U操作而言,计算其答案只需要知道当前列最靠下的那一行

对于L操作而言,计算其答案只需要知道当前行最靠右的那一列

分治的时候动态维护即可

注:这样的话最坏情况会递归20w层,在CF上会爆栈,所以我的代码人为的开了栈空间

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<map>
#include<iostream>
using namespace std;const int maxn=200010;
int n,m;
struct OP{int a,b,id;char c;
}A[maxn];
int mn[maxn<<2];
int ans[maxn];
map<int,bool>vis;bool cmp(const OP &A,const OP &B){return A.a<B.a;}
void ch_read(char &ch){ch=getchar();while(ch<'!')ch=getchar();
}
int Min(int a,int b){return A[a].id<A[b].id?a:b;}
void build(int o,int L,int R){if(L==R){mn[o]=L;return;}int mid=(L+R)>>1;//cout<<mid<<endl;build(o<<1,L,mid);build(o<<1|1,mid+1,R);mn[o]=Min(mn[o<<1],mn[o<<1|1]);
}
int ask(int o,int L,int R,int x,int y){if(L>=x&&R<=y)return mn[o];int mid=(L+R)>>1;if(y<=mid)return ask(o<<1,L,mid,x,y);else if(x>mid)return ask(o<<1|1,mid+1,R,x,y);else return Min(ask(o<<1,L,mid,x,y),ask(o<<1|1,mid+1,R,x,y));
}
void Solve(int L,int R,int Low,int Right){if(L>R)return;int now=ask(1,1,m,L,R);if(vis[A[now].a]){Solve(L,now-1,Low,Right);Solve(now+1,R,Low,Right);return;}vis[A[now].a]=true;if(A[now].c=='U'){ans[A[now].id]=A[now].b-Low;Solve(L,now-1,Low,Right);Solve(now+1,R,Low,A[now].a);}else{ans[A[now].id]=A[now].a-Right;Solve(L,now-1,A[now].b,Right);Solve(now+1,R,Low,Right);}return;
}int main(){int __size__ = 20 << 20; // 20MBchar *__p__ = (char*)malloc(__size__) + __size__;__asm__("movl %0, %%esp\n" :: "r"(__p__));scanf("%d%d",&n,&m);for(int i=1;i<=m;++i){scanf("%d%d",&A[i].a,&A[i].b);ch_read(A[i].c);A[i].id=i;}sort(A+1,A+m+1,cmp);build(1,1,m);Solve(1,m,0,0);for(int i=1;i<=m;++i)printf("%d\n",ans[i]);return 0;
}

  

另外附上官方题解:

还是上面的思路,我们很容易发现:

对于每一行,只需要知道其最靠右覆盖的列

对于每一列,只需要知道其最靠下覆盖的行

我们可以建两棵线段树,分别维护行的信息和列的信息

每次操作分别更改两棵线段树即可

又因为n很大,所以我们需要对行和列离散化

转载于:https://www.cnblogs.com/joyouth/p/5368552.html

codeforces #310 div1 C相关推荐

  1. 【Codeforces #167 Div1 Div2】Solutions

    [A. Dima and Friends] http://www.codeforces.com/contest/272/problem/A 题目大意:n+1个人出手指头,加起来再做类似约瑟夫的出圈,问 ...

  2. CodeForces:103(div1)104(div2)

    文章目录 前言 CF104A Blackjack Description\text{Description}Description Solution\text{Solution}Solution Co ...

  3. CodeForces:372(div1)div373(div2)

    文章目录 前言 CF373A Collecting Beats is Fun Description\text{Description}Description Solution\text{Soluti ...

  4. CodeForces:1103(div1)1104(div2)

    文章目录 前言 CF1104A Splitting into digits Description\text{Description}Description Solution\text{Solutio ...

  5. CodeForces:749(div1)750(div2)

    文章目录 前言 CF450A Jzzhu and Children Description\text{Description}Description Solution\text{Solution}So ...

  6. CodeForces: 360(div1)361(div2)

    文章目录 前言 CF361A Levko and Table Description\text{Description}Description Solution\text{Solution}Solut ...

  7. codeforces:1361(div1)1362(div2):总结

    文章目录 前言 1362-A. Johnny and Ancient Computer 解析 1362-B - Johnny and His Hobbies 解析 1362-C - Johnny an ...

  8. codeforces #309 div1 D

    求最小值最大显然是要二分 二分之后转换成了判定性问题 我们考虑哪些点一定不能选 显然是将所有可选点选中之后依然不满足条件的点不能选 那么我们不妨维护一个堆,每次取出堆顶看看是否满足条件 不满足条件就p ...

  9. 鱼的记忆[较为重要的知识点/技巧]

    传说中鱼只有7s的记忆. 而我不足7s的记忆. 真是悲伤TAT 记了什么东西,一会就忘记了. 我当时初中的时候想去自学高中课程-- 但是自己完全没看懂. 其实不是自己看不懂而是自己"觉得&q ...

最新文章

  1. barplot参数 python_Python零基础入门Python数据分析最好的实战项目
  2. 触发transition的几种方式--转
  3. 团队开发冲刺第二阶段_4
  4. 什么是pretext tasks?
  5. 利用BADI ME_PROCESS_PO_CUST進行PO check
  6. C语言中malloc函数产生的内存泄漏问题
  7. 90年代微型计算机,版本控制如何在80年代和90年代的当今微型计算机上工作?
  8. Microsoft SQL Server 2000整合规划
  9. ​php mysql教学管理系统计算机毕业设让网站作品
  10. 自动化测试——接口自动化——requests用法
  11. Evernote 强力替代品:开源加密笔记本 Joplin
  12. BMFont 字体生成工具使用
  13. 如何动态的修改安卓APP名字和桌面图标
  14. 全面的结构专业英语词汇 (三)
  15. android 上拉抽屉,Flutter上拉抽屉实现
  16. Linux 3.x 的platform
  17. 1078 字符串压缩与解压
  18. 国外设计博客小组收集
  19. 栈内存与堆内存的简单理解
  20. 2020年茶艺师(初级)考试题及茶艺师(初级)考试题库

热门文章

  1. 2022-2028年中国网络直播行业深度调研及投资前景预测报告
  2. C++ 笔记(32)— 预处理、文件包含include、宏替换define、条件包含ifndef、define
  3. Go 学习笔记(61)— Go 高阶函数、函数作为一等公民(函数作为输入参数、返回值、变量)的写法
  4. detach detach_ pytorch
  5. 中继TensorRT集成
  6. Recommenders with TensorRT
  7. 将视频插入视频:CVPR2019论文解析
  8. Python : IndentationError: expected an indented block
  9. java static 作用详解
  10. angular.isUndefined()