Codeforces 1018D D. Order book
解法:用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的更多相关文章
- Codeforces - 702A - Maximum Increase - 简单dp
DP的学习计划,刷 https://codeforces.com/problemset?order=BY_RATING_ASC&tags=dp 遇到了这道题 https://codeforce ...
- 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 ...
- Codeforces Beta Round #8 C. Looking for Order 状压
C. Looking for Order 题目连接: http://www.codeforces.com/contest/8/problem/C Description Girl Lena likes ...
- B. Order Book(Codeforces Round #317 )
B. Order Book time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces 993E Nikita and Order Statistics [FFT]
洛谷 Codeforces 思路 一开始想偏想到了DP,后来发现我SB了-- 考虑每个\(a_i<x\)的\(i\),记录它前一个和后一个到它的距离为\(L_i,R_i\),那么就有 \[ an ...
- codeforces 637B B. Chat Order(map,水题)
题目链接: B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Order Book 模拟
原题链接:http://codeforces.com/contest/572/problem/B 题意 很迷,自行看题. 题解 看懂题就会做了 代码 #include<iostream> ...
- codeforces 8C. Looking for Order 状压dp
题目链接 给n个物品的坐标, 和一个包裹的位置, 包裹不能移动. 每次最多可以拿两个物品, 然后将它们放到包里, 求将所有物品放到包里所需走的最小路程. 直接状压dp就好了. #include < ...
- codeforces 8c Looking for Order
https://vjudge.net/problem/CodeForces-8C 题意: 一个平面上放着许多东西,每个东西都有一个坐标,最开始一个人在一个起始坐标,她出发去拿东西,一次要么拿一件东西, ...
随机推荐
- 【Training versus Testing】林轩田机器学习基石
接着上一讲留下的关子,机器学习是否可行与假设集合H的数量M的关系. 机器学习是否可行的两个关键点: 1. Ein(g)是否足够小(在训练集上的表现是否出色) 2. Eout(g)是否与Ein(g)足够 ...
- Python 绘制棋盘
import turtle pen = turtle.Pen() pen.speed(10) width = 30 # 格子宽度 count = 18 # 横向纵向格子数 o = width * co ...
- redhat 安装python3
一.首先,官网下载python3的所需版本. wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz 想下载到那个文件夹下就先进入到 ...
- django-settings里mysql连接配置
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'dailyfresh', 'HOST': 'loca ...
- 聊聊、Spring ServletContainerInitializer
我们平时用 Java 注解很多,例如 @Configuration.@Component.@Service,我们习惯于通过 XML 方式来实现 Web,而用 Java 注解方式来实现 Web 却很少. ...
- QQ网页强制聊天,微博一键关注
<!doctype html> <!-- 微博关注需要的js --> <html xmlns:wb="http://open.weibo.com/wb" ...
- HDU 4472 Count (DP)
题目:问n个节点构成完全对称的树有多少种方法. 因为树是完全对称的,所以它的子树也是完全对称的. 对于每个树,拿出一个根节点,枚举剩下的节点能拆分成多少个子树. #include <cstdio ...
- 【bzoj1856】[Scoi2010]字符串 Catalan数
题目描述 lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数.现在lxhgww想要知道满足 ...
- Java设计模式中适配器模式的实现方法
在Java开发中,我们常常需要用到Java接口型模式中的适配器模式,那适配器设计模式到底是什么模式呢? 适配器模式(Adapter)就是把一个类的接口变换成客户端所期待的另一种接口,从而使原本接口不匹 ...
- HDU1520 树形DP入门
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...