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. 如何配置Drupal数据库信息?

    Drupal的数据库连接信息通过文件settings.php中的变量$databases设置.变量$databases是一个二维的数组,第一维称为key,第二维称为target.使用这种方式可以处理多 ...

  2. [python]使用pexpect模块进行批量scp

    #!/usr/bin/env python# -*- coding: utf-8 -*- #wangxiaofei #awcloud自动化测试 import time,osimport threadi ...

  3. 【LeetCode】169 - Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  4. 解决android.os.NetworkOnMainThreadException

    好久不写Android代码手都生了,找出自己之前写的程序发现跑不了了,也没啥特别的错误提示,就看到一句有用的错误Caused by: android.os.NetworkOnMainThreadExc ...

  5. 【转】requirejs简单入门

    博主今天正式工作啦,工作中用到了js模块化技术,这里转来一个入门教程,很易懂,转给同样刚入门的你们~~ 原地址:http://www.ruanyifeng.com/blog/2012/11/requi ...

  6. c语言的几个重要知识点

      内存结构 这是核心中的核心,请仔细看完,充分理解,否则请不要看下一节内容. 每个程序一启动都有一个大小为4GB的内存,这个内存叫虚拟内存,是概念上的,真正能用到的,只是很小一部分,一般也就是在几百 ...

  7. 关于面试mysql优化的几点纪要

    1.减少查询次数 ,如何减少 ?  2. 表结构优化,如何优化 ? 3. 列选取原则  ? 4.建索引原则   ? 5.mysql语句优化 ?   6.增加mysql处理性能 ? 通过这几点, 再来说 ...

  8. nodejs cmd

    引入系统模块 var exec = require('child_process').exec; cmd.js var exec = require('child_process').exec; va ...

  9. eCryptfs文件系统测试

    650) this.width=650;" onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" ...

  10. 利用AuthorizeAttribute属性简单避免 MVC 中的跨域攻击

    跨域攻击---自然来路页面和目标页面不在同一个域下,所以直接判断来路域和当前自己的域就可以了. 可以广泛应用于表单提交,ajax调用或者某些不想让用户直接输入网址看到的页面 [csharp] view ...