CQOI2009中位数图
原来在vijos上做过,当时根本看不懂
现在看起来这么水……
x记录从b向左连续走比k大的有多少个
y记录从b向右连续走比k大的有多少个
最后根据乘法原理乘一下
不过要加上x[0]+y[0]+1
因为实际上满足条件的序列有四种情况:
一、只选b,即为1
二、只在b左边选,即为x[0]
三、只在b右边选,即为y[0]
四、在两边都选,即为x[i]*y[-i]
Q.E.D
代码:
var i,n,k,tmp:longint;
sum,ans:int64;
x,y:array[-..] of longint;
a:array[..] of longint;
procedure init;
begin
readln(n,tmp);
for i:= to n do
begin
read(a[i]);
if a[i]=tmp then k:=i;
end;
end;
procedure main;
begin
fillchar(x,sizeof(x),);
fillchar(y,sizeof(y),);
for i:=k- downto do
if a[i]>tmp then a[i]:= else a[i]:=-;
sum:=;
for i:=k- downto do
begin
sum:=sum+a[i];
inc(x[sum]);
end;
for i:=k+ to n do
if a[i]>tmp then a[i]:= else a[i]:=-;
sum:=;
for i:=k+ to n do
begin
sum:=sum+a[i];
inc(y[sum]);
end;
ans:=;
for i:=-n to n do inc(ans,x[i]*y[-i]);
inc(ans,x[]);inc(ans,y[]);
writeln(ans+);
end;
begin
init;
main;
end.
CQOI2009中位数图的更多相关文章
- BZOJ 1303 CQOI2009 中位数图 水题
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2340 Solved: 1464[Submit][Statu ...
- BZOJ 1303: [CQOI2009]中位数图【前缀和】
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2737 Solved: 1698[Submit][Statu ...
- 【BZOJ1303】[CQOI2009]中位数图(模拟)
[BZOJ1303][CQOI2009]中位数图(模拟) 题面 BZOJ 洛谷 题解 把大于\(b\)的数设为\(1\),小于\(b\)的数设为\(-1\).显然询问就是有多少个横跨了\(b\)这个数 ...
- bzoj千题计划175:bzoj1303: [CQOI2009]中位数图
http://www.lydsy.com/JudgeOnline/problem.php?id=1303 令c[i]表示前i个数中,比d大的数与比d小的数的差,那么如果c[l]=c[r],则[l+1, ...
- bzoj 1303: [CQOI2009]中位数图 数学
1303: [CQOI2009]中位数图 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...
- BZOJ1303 [CQOI2009]中位数图 【乱搞】
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 3086 Solved: 1898 [Submit][Sta ...
- BZOJ1303 [CQOI2009]中位数图
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- 【BZOJ】1303: [CQOI2009]中位数图(特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1303 依旧是题解流,,,不看题解没法活,,,第一眼就是瞎搞,然后就是暴力,显然TLE..题解啊题解. ...
- bzoj 1303: [CQOI2009]中位数图
题目链接 给n个数,一个值b, 统计所有以b为中位数的序列的个数.序列长度为奇数.数字在1-n之间, 每个数只出现一次. 如果一个数大于b, 那么将他赋值为1, 小于b赋值为-1, 记录数组中b出现的 ...
- BZOJ1303 [CQOI2009]中位数图 其他
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1303 题意概括 给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b.中位数 ...
随机推荐
- Python生成验证码
#!/usr/bin/env python #coding:utf8 import random #方法1: str_code='zxcvbnmasdfghjklqwertyuiopZXCVBNMAS ...
- Linux学习系列之Linux入门(一)linux安装与入门
第一篇:安装并配置Linux开发环境 一.安装linux: 主要安装Linux的发行版,到目前为之,主要的发行版有: 比较常用的是Ubuntu.redhat和centOS,主要的安装方法详细: Ubu ...
- 1037. Magic Coupon (25)
#include<iostream> #include<vector> #include<stdio.h> #include<algorithm> us ...
- 二、mysql数据类型
.数值型 ) decimal最大支持65位 ) 最大支持10位的二进制存储模式 bin(column),hex(column) 使用bin(二进制查看)或hex(十六进制查看)查看bit类型数据 .时 ...
- 后台启动mysql ,redis
mysqld_safe --user=mysql & redis.conf daemonize no修改为daemonize yes
- 内置对象之Cookie
if (!this.IsPostBack) { try { HttpCookie MyCookie = new HttpCookie("MyCookie"); MyCookie.V ...
- HTML 菜单 a 标签跳转本页面并追加参数
代码如下: <!-- BEGIN 追加URL的参数 --> <script type="text/javascript"> function setUrl( ...
- Head First设计模式悟道
暂时包括 策略模式,观察者,装饰模式,工厂模式,抽象工厂模式,后续会继续补充中,纯属个人总结用,不喜勿喷, 源代码见: 传送门 public class NYPizzaIngredientFactor ...
- HubbleDotNet开源全文搜索组件相关资源
系统简介 HubbleDotNet 是一个基于.net framework 的开源免费的全文搜索数据库组件.开源协议是 Apache 2.0.HubbleDotNet提供了基于SQL的全文检索接口,使 ...
- csu 1303 Decimal (数论题)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1303 1303: Decimal Time Limit: 1 Sec Memory Limit: ...