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 题意: 一个平面上放着许多东西,每个东西都有一个坐标,最开始一个人在一个起始坐标,她出发去拿东西,一次要么拿一件东西, ...
随机推荐
- DWZ(J-UI)之路:错误
1:关于左侧点击会把右边小窗口替换掉,导致右边永远只有一个小窗口. 方法:因为缺少了这个—— <li><a href="/admin/demo/index" ta ...
- Oz 创建Windows2008R2镜像
此tdl和auto文件只可定义windows disk bus以ide模式启动,不支持virtio. <template> <name>Windows-gushiren< ...
- 平衡二叉树(AVL)
AVL就是优化二叉查找树 平衡因子不大于1 左 < 根 < 右 具体看代码 #include<bits/stdc++.h> using namespace std; typed ...
- 线段树 (区间更新,区间查询) poj http://poj.org/problem?id=3468
题目链接 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...
- 通过设计表快速了解sql语句中字段的含义
打开Navicat-------> 选择数据库 ------->右键设计表------>查看下方注释
- ArcGIS 创建要素时提示“表已经被注册(table already registered)”
今天一位实施大哥在ArcCatalog中要重建一个要素类,所以就在ArcCatalog中连接上Oracle数据库,直接删除了要素类,然后重新创建了一个新的要素类,可是却报错“表已经被创建”,并提示不可 ...
- TensorFlow 模型文件
在这篇 TensorFlow 教程中,我们将学习如下内容: TensorFlow 模型文件是怎么样的? 如何保存一个 TensorFlow 模型? 如何恢复一个 TensorFlow 模型? 如何使用 ...
- [bzoj] 1085 骑士精神 || ID-DFS
原题 找到最少的步数成为目标状态. IDDFS(限制层数的dfs)即可 #include<cstdio> #include<algorithm> using namespace ...
- java中的URLEncoder.encode对应JS中用decodeURIComponent,js和java编码,解码
用get请求传中文,经常搞到乱码,这几天搞搞这个东西,总结一下,以方便以后处理这类的问题. Java代码中的URLEncoder.encode方法和JS的encodeURIComponent功能差不多 ...
- Python学习笔记(Django篇)——2、创建第一个django应用
在helloworld工程的基础上,我们准备创建第一个基于web的django应用,把这个应用名字命名为demo 首先,是如何创建这个应用包,当然第一选择我们可以进入到cmd中,执行如下命令 py ...