解法:用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. 《Cracking the Coding Interview》——第1章:数组和字符串——题目8

    2014-03-18 02:12 题目:判断一个字符串是否由另一个字符串循环移位而成. 解法:首先长度必须相等.然后将第一个串连拼两次,判断第二个串是否在这个连接串中. 代码: // 1.8 Assu ...

  2. ymal

    https://blog.csdn.net/beginya/article/details/76768968 https://www.jianshu.com/p/97222440cd08

  3. 一个初学者的辛酸路程-前端js

    内容回顾: 1.CSS的基本概念: 层叠样式表. 2.CSS的三种书写方式 ① 行内样式 <div style="color: red;">sdfdsf</div ...

  4. redhat 安装python3

    一.首先,官网下载python3的所需版本. wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz 想下载到那个文件夹下就先进入到 ...

  5. React03 移动端跨平台开发

    目录 React-day03 RN移动端开发 了解React-Native 了解React-Native工作流程 创建第一个React-Native项目 * 了解React-Native项目及结构 开 ...

  6. php 链接转二维码图片

    // 类库下载地址 https://sourceforge.net/projects/phpqrcode/files/ $value = 'www.baidu.com';//二维码内容 $errorC ...

  7. php中普通方法和静态方法的区别以及抽象类和接口

    实例化类产生对象.class fenbi{ //普通成员,属于对象 public $length = "10cm"; //静态成员,静态变量,属于类. public static ...

  8. zoj 1508 Intervals (差分约束)

    Intervals Time Limit: 10 Seconds      Memory Limit: 32768 KB You are given n closed, integer interva ...

  9. [AtCoder ARC093F]Dark Horse

    题目大意:有$2^n$个人,每相邻的两个人比赛一次.令两个人的编号为$a,b(a\leqslant b)$,若$a\neq 1$,则$a$的人获胜:否则若$b\in S$则$b$获胜,不然$1$获胜. ...

  10. [codeforces] 359D Pair of Numbers

    原题 RMQ st表棵题 要想让一个区间里的所有数都可以整除其中一个数,那么他一定是这个区间内的最小值,并且同时是这个区间的gcd.然后这个问题就转化成了RMQ问题. 维护两个st表,分别是最小值和g ...