C. Case of Chocolate

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/555/problem/C

Description

Andrewid the Android is a galaxy-known detective. Now he does not investigate any case and is eating chocolate out of boredom.

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的更多相关文章

  1. Codeforces Round #310 (Div. 1) C. Case of Chocolate (线段树)

    题目地址:传送门 这题尽管是DIV1的C. . 可是挺简单的. .仅仅要用线段树分别维护一下横着和竖着的值就能够了,先离散化再维护. 每次查找最大的最小值<=tmp的点,能够直接在线段树里搜,也 ...

  2. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  3. 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

  4. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. WINHEX 使用教程

    Winhex有完善的分区管理功能和文件管理功能,能自动分析分区链和文件簇链,能对硬盘进行不同方式不同程度的备份,甚至克隆整个硬盘:它能够编 辑任何一种文件类型的二进制内容(用十六进制显示)其磁盘编辑器 ...

  2. 【LeetCode 236】Lowest Common Ancestor of a Binary Tree

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  3. A.xml

    pre{ line-height:1; color:#1e1e1e; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#627cf6; ...

  4. PHP 解压zip文件的函数封装

    /** * zip文件解压 * * @param $zipFilePath zip文件的路径,可以不加zip文件后缀.如果其他类型的文件伪装成zip解压也会失败 * @param $directory ...

  5. Javascript类型转换表

    各种类型的值 转换为各种类型 String Number Boolean Object undefined "undefined" NaN false 报错 null " ...

  6. Maven默认周期与插件

    运行 cmd mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId= ...

  7. Python和Django的Third Libraby分类汇总

    这些第三方包与Python和Django一起构成了强大的生态系统,自己在开发时大大减小工作难度和工作量, 这些包基本上能满足我们的大部分需求.人与人的差距,其中一点是你知道的比他多,这样你就能大大提高 ...

  8. 【128】Word中的VBA

    通过查找关键字,然后删除整段文字的实现! Sub 删除查找含关键词的行() Dim KeyWord As String KeyWord = InputBox("请输入关键词(词长不限,中英均 ...

  9. java线性表学习笔记(一)

    线性表是一种按顺序储存数据是的常用结构,大多数的线性表都支持以下的典型操作: 从线性表提取插入删除一个数据: 找出线性表中的某一个元素: 找出线性表中的元素: 确定线性表中是否包含某一个元素,确定线性 ...

  10. resharper 7.x 注册码key

    user:dobit sn:G/YgFyekI7EL0oBc5YBWKI5WCi3pwXWP