Codeforces Round #310 (Div. 1) C. Case of Chocolate set
C. Case of Chocolate
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/555/problem/C
Description
A bar of chocolate can be presented as an n × n table, where each cell represents one piece of chocolate. The columns of the table are numbered from 1 to n from left to right and the rows are numbered from top to bottom. Let's call the anti-diagonal to be a diagonal that goes the lower left corner to the upper right corner of the table. First Andrewid eats all the pieces lying below the anti-diagonal. Then he performs the following q actions with the remaining triangular part: first, he chooses a piece on the anti-diagonal and either direction 'up' or 'left', and then he begins to eat all the pieces starting from the selected cell, moving in the selected direction until he reaches the already eaten piece or chocolate bar edge.
After each action, he wants to know how many pieces he ate as a result of this action.
Input
The first line contains integers n (1 ≤ n ≤ 109) and q (1 ≤ q ≤ 2·105) — the size of the chocolate bar and the number of actions.
Next q lines contain the descriptions of the actions: the i-th of them contains numbers xi and yi (1 ≤ xi, yi ≤ n, xi + yi = n + 1) — the numbers of the column and row of the chosen cell and the character that represents the direction (L — left, U — up).
Output
Print q lines, the i-th of them should contain the number of eaten pieces as a result of the i-th action.
Sample Input
6 5
3 4 U
6 1 L
2 5 L
1 6 U
4 3 U
Sample Output
4
3
2
1
2
HINT
Pictures to the sample tests:
The pieces that were eaten in the same action are painted the same color. The pieces lying on the anti-diagonal contain the numbers of the action as a result of which these pieces were eaten.
In the second sample test the Andrewid tries to start eating chocolate for the second time during his fifth action, starting from the cell at the intersection of the 10-th column and the 1-st row, but this cell is already empty, so he does not eat anything.
题意
见hint,图很清楚,注意x+y==n+1
题解:
比B题简单呀……直接set搞一搞就好了
U的就找L的
L就找U的……
然后搞一搞就好了~
代码
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef unsigned long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2000001
#define mod 1000000007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} //************************************************************************************** set<pair<int,int> > s;
map<int,int>m; int main()
{
int n=read(),q=read();
s.insert(make_pair(,));
s.insert(make_pair(n+,));
for(int i=;i<q;i++)
{
int x=read(),y=read();
char c;scanf("%c",&c);
if(m.count(x))
{
puts("");
continue;
}
if(c=='U')
{
pair<int,int> p=*s.lower_bound(pair<int,int>(x,-));
if(p.second==)
m[x]=p.first-x+m[p.first];
else
m[x]=p.first-x;
s.insert(pair<int,int>(x,));
}
else
{
set<pair<int,int> >::iterator it=--s.lower_bound(pair<int,int>(x,-));
if(it->second==)
m[x]=x-it->first+m[it->first];
else
m[x]=x-it->first;
s.insert(pair<int,int>(x,));
}
printf("%d\n",m[x]);
}
}
Codeforces Round #310 (Div. 1) C. Case of Chocolate set的更多相关文章
- Codeforces Round #310 (Div. 1) C. Case of Chocolate (线段树)
题目地址:传送门 这题尽管是DIV1的C. . 可是挺简单的. .仅仅要用线段树分别维护一下横着和竖着的值就能够了,先离散化再维护. 每次查找最大的最小值<=tmp的点,能够直接在线段树里搜,也 ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题
B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题
A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- Codeforces Round #310 (Div. 1) B. Case of Fugitive set
B. Case of Fugitive Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/555/p ...
- Codeforces Round #310 (Div. 1) A. Case of Matryoshkas 水题
C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- Codeforces Round #310 (Div. 1) B. Case of Fugitive(set二分)
B. Case of Fugitive time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- win7 下配置resin的一些tip
一.如何查看jdk安装目录: 通过不同方法搜索javac看看, javac.exe 是java的编译器: 可用的搜索方法: 1.cmd 控制台: where javac 2.开始菜单的搜索: 一直到 ...
- 修改 AndroidManifest minSdkVersion 的方法
1.修改AndroidManifest文件 使用16进制编辑器检索位置:FF FF FF FF 08 00 00 10 ?? 将??替换为原APK的minSdkVersion对应的16进制 ...
- 基于opencv的手写数字识别(MFC,HOG,SVM)
参考了秋风细雨的文章:http://blog.csdn.net/candyforever/article/details/8564746 花了点时间编写出了程序,先看看效果吧. 识别效果大概都能正确. ...
- 使用Eclipse的几个必须掌握的快捷方式(能力工场小马哥收集)
“工若善其事,必先利其器”,感谢Eclipse,她 使我们阅读一个大工程的代码更加容易,在阅读的过程中,我发现掌握几个Eclipse的快捷键会使阅读体验更加流畅,写出来与诸君分享,欢迎补充. 1. C ...
- HDU2648:Shopping(DKBR_hash)
题目链接 题意: 给出n个字符串,接下来m天,每天每个字符串要增加对应的值,询问“memory”每天的排名 分析: 用hash表hash出每个字符串对应得值,然后放入二维数组(防止地址冲突),m天,输 ...
- 第三百二十二天 how can I 坚持
昨晚好像一直在做梦,模模糊糊的,其实很难受. 真不知道该怎么办了,是没有勇气,还是怕什么,总之, 不知道该咋办了. 搞不懂. 回来第二天了,节奏又一点的开始了,一年又会很快过去. 刘松说要来北京,整天 ...
- CSS 居中大全
<center> text-align:center 在父容器里水平居中 inline 文字,或 inline 元素 vertical-align:middle 垂直居中 inline 文 ...
- Python基础 条件、循环
1.条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. if if语句执行有个特点,它是从上往下判断,如果在某个判断上是True,把该判断对应的 ...
- ASP.NET的分页方法(二)
第二讲主要使用到了常用的分页控件aspnetpager,这里对他就行一个简单的应用,具体大家可以到杨涛的博客上去寻找相关的DLL, 首先要先引用AspNetPager.dll,然后把这个DLL同时添加 ...
- SQL2005/8数据库提示单个用户无法操作的解决方法
原因分析: 是操作数据库的用户被锁定了,思路是通过查找目标用户,将其解锁即可,可是这样太麻烦了. 解决办法执行如下sql: USE master; GO DECLARE @SQL VARCHAR( ...