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 题意: 一个平面上放着许多东西,每个东西都有一个坐标,最开始一个人在一个起始坐标,她出发去拿东西,一次要么拿一件东西, ...
随机推荐
- web前端开发总结(未完)
由于我也是接触前端开发不久,所以呢,自己也会做点小功课,于是,我把前端能够用到的知识稍稍做了下总结,总结的不全面,以后会慢慢完善的! 移动前端开发基础 (总结----待完善)1.移动前端开发:简而言之 ...
- 为什么要内存对齐 Data alignment: Straighten up and fly right
转载于http://blog.csdn.net/lgouc/article/details/8235471 为了速度和正确性,请对齐你的数据. 概述:对于所有直接操作内存的程序员来说,数据对齐都是很重 ...
- Windows10使用pip安装python包时报错-UnicodeDecodeError: 'ascii' codec c
本人是Windows10,用的方法2解决的 原文链接http://blog.csdn.net/all_over_servlet/article/details/45112221 先交待下开发环境: 操 ...
- Jmeter微信小程序接口测试
最近公司新项目组开发一款微信小程序电商平台,为了更好保证产品质量,因此提出了需要进行接口测试. 从接口本身来讲,对其测试与其他项目应该是一样的.所以不难理解,我们要对小程序的接口测试需要准备的 材料有 ...
- SELECTORS模块实现并发简单版FTP
环境:windows, python 3.5功能:使用SELECTORS模块实现并发简单版FTP允许多用户并发上传下载文件 结构:ftp_client ---| bin ---| start_clie ...
- drf解决跨域问题 使用 django-corse-headers扩展
跨域CORS 使用django-corse-headers扩展 安装 pip install django-cors-headers 添加应用 INSTALLED_APPS = ( ... 'cors ...
- Python全栈工程师(while、占位符)
ParisGabriel Python 入门基础 UnicodeASCII 用8个位表示文字 ,最高位一定是零,低七位表示数值Unicode是由16个位组成的(65535) 最 ...
- python之路——网络编程
一.楔子 你现在已经学会了写python代码,假如你写了两个python文件a.py和b.py,分别去运行,你就会发现,这两个python的文件分别运行的很好.但是如果这两个程序之间想要传递一个数据, ...
- React01补充
使用yarn安装脚手架 npm i -g yarn npm uninstall -g create-react-app yarn global add create-react-app create- ...
- 那些牛掰的 HTML5的API(二)
1:视频播放器 2:地理定位 我们的支持html5 的浏览器给我们提供一个接口(api),可以用来获取你当前的位置. 主要是通过geolocation(地理位置),对象 ,去访问硬件,来获取到经纬度. ...