解法:用l,r分别代表buy的最大值和sell的最小值,add时,若添加的值在l,r之间,则该值有可能作为下一次accept的值

accept x时,x只能在区间[l,r]中,否则无解,若x为l或r,ans不变,否则,x的类型可以是sell或buy,ans*=2,更新l,r值为x的左右值

结尾是add而没有accept时,需要维护出现在l,r之间的值得数量,这些值可以是buy或sell,ans*=(ins+1)即可

(结尾*=(ins+1)想成了+=(ins+1),记录一下自己犯的小错误,小错误最烦人)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<climits>
#include<bitset>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("input.in", "r", stdin);freopen("output.in", "w", stdout);
#define left asfdasdasdfasdfsdfasfsdfasfdas1
#define tan asfdasdasdfasdfasfdfasfsdfasfdas
typedef long long ll;
typedef unsigned int un;
const int desll[][]={{,},{,-},{,},{-,}};
const ll mod=1e9+;
const int maxn=4e5+;
const int maxm=1e6+;
const double eps=1e-;
int m,n;
int ar[maxn];
set<int> se;
char ch[];
int maxx=; int main()
{
scanf("%d",&n);
int ans=;
int l=,r=maxx;
bool ma=true;
int ins=;
for(int i=;i<n;i++){
int x;
scanf("%s",ch);
scanf("%d",&x);
if(ch[]=='D'){
if(se.count(x)== && l<x && x<r){
se.insert(x);
ins++;
}
else if(se.count(x)==){
ma=;
}
else{
se.insert(x);
}
}
else{
if(se.count(x)== && x<=r && x>=l){
if(x!=l&&x!=r)ans = ans*%mod;
set<int>::iterator iter=se.find(x);
if(iter==se.begin())l=;
else{
iter--;
l=*iter;
iter++;
}
se.erase(iter++);
if(iter==se.end())r=maxx;
else{
r=*iter;
}
}
else{
ma=;
}
ins=;
}
}
if(ins){
ans = 1LL*ans*(ins+)%mod;
}
if(ma)printf("%d\n",ans);
else printf("0\n"); return ;
}

Codeforces 1018D D. Order book的更多相关文章

  1. Codeforces - 702A - Maximum Increase - 简单dp

    DP的学习计划,刷 https://codeforces.com/problemset?order=BY_RATING_ASC&tags=dp 遇到了这道题 https://codeforce ...

  2. Codeforces Beta Round #8 C. Looking for Order 状压dp

    题目链接: http://codeforces.com/problemset/problem/8/C C. Looking for Order time limit per test:4 second ...

  3. Codeforces Beta Round #8 C. Looking for Order 状压

    C. Looking for Order 题目连接: http://www.codeforces.com/contest/8/problem/C Description Girl Lena likes ...

  4. B. Order Book(Codeforces Round #317 )

    B. Order Book time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. Codeforces 993E Nikita and Order Statistics [FFT]

    洛谷 Codeforces 思路 一开始想偏想到了DP,后来发现我SB了-- 考虑每个\(a_i<x\)的\(i\),记录它前一个和后一个到它的距离为\(L_i,R_i\),那么就有 \[ an ...

  6. codeforces 637B B. Chat Order(map,水题)

    题目链接: B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Order Book 模拟

    原题链接:http://codeforces.com/contest/572/problem/B 题意 很迷,自行看题. 题解 看懂题就会做了 代码 #include<iostream> ...

  8. codeforces 8C. Looking for Order 状压dp

    题目链接 给n个物品的坐标, 和一个包裹的位置, 包裹不能移动. 每次最多可以拿两个物品, 然后将它们放到包里, 求将所有物品放到包里所需走的最小路程. 直接状压dp就好了. #include < ...

  9. codeforces 8c Looking for Order

    https://vjudge.net/problem/CodeForces-8C 题意: 一个平面上放着许多东西,每个东西都有一个坐标,最开始一个人在一个起始坐标,她出发去拿东西,一次要么拿一件东西, ...

随机推荐

  1. Pascal ASCII和文本的转换

    用于帮助新手理解ASCII码和字符型与整型的一段小程序,转载请注明出处 例如:输入 I love you 打印 73 32 108 111 118 101 32 121 111 117 13 10 P ...

  2. 【Perceptron Learning Algorithm】林轩田机器学习基石

    直接跳过第一讲.从第二讲Perceptron开始,记录这一讲中几个印象深的点: 1. 之前自己的直觉一直对这种图理解的不好,老按照x.y去理解. a) 这种图的每个坐标代表的是features:fea ...

  3. 导出csv用excel打开后数字不用科学计数法显示(0123456显示123456)

    从这儿抄过来的: http://zhejiangyinghui.iteye.com/blog/1149526 最近写了一个生成csv的程序,生成的csv其中有一列数字长度为13位,csv中查看没有问题 ...

  4. 【非原创】tomcat 安装时出现 Failed to install Tomcat7 service

    tomcat 安装时出现 Failed to install Tomcat7 service 今天在安装tomcat时提示 Failed to install Tomcat7 service了,花了大 ...

  5. sql的nvl()函数

    一NVL函数是一个空值转换函数 NVL(表达式1,表达式2) 如果表达式1为空值,NVL返回值为表达式2的值,否则返回表达式1的值. 该函数的目的是把一个空值(null)转换成一个实际的值.其表达式的 ...

  6. 孤荷凌寒自学python第十八天python变量的作用范围

    孤荷凌寒自学python第十八天python函数的形参与变量的范围 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 一.在python的函数中各种不同的形式参数在定义的先后顺序上有规定: 必须 ...

  7. SVN客户端使用手册

    使用svn进行源代码版本控制,代码管理利器. 优点: 使用方便,与文件管理器集成.速度快,稳定. 实现代码比较,比如对历史和当前代码进行比较. 解决多人同时编写代码时代码重复修改困难. 安装: 下载网 ...

  8. ocrosoft Contest1316 - 信奥编程之路~~~~~第三关 问题 J: 外币兑换

    http://acm.ocrosoft.com/problem.php?cid=1316&pid=9 题目描述 小明刚从美国回来,发现手上还有一些未用完的美金,于是想去银行兑换成人民币.可是听 ...

  9. 【bzoj2401】陶陶的难题I “高精度”+欧拉函数+线性筛

    题目描述 求 输入 第一行包含一个正整数T,表示有T组测试数据.接下来T<=10^5行,每行给出一个正整数N,N<=10^6. 输出 包含T行,依次给出对应的答案. 样例输入 7 1 10 ...

  10. CF 1103B Game with modulo

    题目 $a, x$ 是正整数.显然有 \begin{aligned} x \ge 2x \pmod{a} \implies a \le 2x \end{aligned} 若 $x \le a$ 则 \ ...