Magnetic Storms
http://acm.timus.ru/problem.aspx?space=1&num=1126
简单的线段树求区间最值
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=;
int a[N],ans ;
struct node
{
int l,r,Max;
} tree[N*];
void build(int t,int l,int r)
{
tree[t].l = l;
tree[t].r = r;
if (l==r)
{
tree[t].Max = a[r];
return ;
}
int mid = (l+r)>>;
build(t<<,l,mid);
build(t<<|,mid+,r);
tree[t].Max = max(tree[t<<].Max,tree[t<<|].Max);
}
void Query(int t,int l,int r)
{
if (l <= tree[t].l && r>= tree[t].r)
{
ans = max(ans,tree[t].Max);
return ;
}
int mid = (tree[t].l+tree[t].r)>>;
if (r <= mid)
Query(t<<,l,r);
else if (l > mid)
Query(t<<|,l,r);
else
{
Query(t<<,l,mid);
Query(t<<|,mid+,r);
}
}
int main()
{
int m,n = ,x;
scanf("%d",&m);
while()
{
scanf("%d",&x);
if (x == -)
break;
a[n++] = x;
}
build(,,n);
for (int i = ; i <= n-m; i++)
{
ans = ;
Query(,i,m+i-);
printf("%d\n",ans);
}
return ;
}
Magnetic Storms的更多相关文章
- ural1126 Magnetic Storms
Magnetic Storms Time limit: 0.5 secondMemory limit: 64 MB The directory of our kindergarten decided ...
- 1126. Magnetic Storms(单调队列)
1126 最简单的单调队列应用吧 单调队列是指在一个队列中各个元素单调 递增(或者递减),并且各个元素的下标单调 递增. 单调队列的大体操作 进队时,将进队的元素为e,从队尾往前扫描,直到找到一个不大 ...
- ural 1126 Magnetic Storms
http://acm.timus.ru/problem.aspx?space=1&num=1126 #include <cstdio> #include <cstring&g ...
- NOTES : A Model of Gas Exchange for Hyperpolarized Xe(129) Magnetic Resonance of the Lung
NOTES : A Model of Gas Exchange for Hyperpolarized Xe(129) Magnetic Resonance of the Lung 背景知识: Ga ...
- Transcranial magnetic stimulation (TMS)
Transcranial magnetic stimulation (TMS) Effect of Transcranial Magnetic Stimulation on Free Will Tra ...
- MaLoc: a practical magnetic fingerprinting approach to indoor localization using smartphones
https://www.indooratlas.com/ MaLoc: a practical magnetic fingerprinting approach to indoor localizat ...
- Magnetic Fingerprinting Approach to Indoor Localization
Magnetic Fingerprinting Approach to Indoor Localization
- HearthBuddy Magnetic 磁力
https://hearthstone.gamepedia.com/Magnetic Magnetic is an ability exclusive to certain Mech minions ...
- LA 4064 Magnetic Train Tracks
题意:给定平面上$n(3\leq n \leq 1200)$个无三点共线的点,问这些点组成了多少个锐角三角形. 分析:显然任意三点可构成三角形,而锐角三角形不如直角或钝角三角形容易计数,因为后者有且仅 ...
随机推荐
- [Algorithm] 7. Serialize and Deserialize Binary Tree
Description Design an algorithm and write code to serialize and deserialize a binary tree. Writing t ...
- Python习题之列表排序,4种方法
def sort_list_method_1(a): return sorted(a) print(sort_list_method_1([1, 4, 2])) def sort_list_metho ...
- Ubuntu notes
ubuntu notes Table of Contents 1. backup data 2. Basics Ubuntu 3. Install, uninstall packages 4. Bas ...
- DemoKit编译过程
E:\Project_code\EAE\src_rev_24139_A95LYD\Project\DemoKit>make release Checking uITRON - DemoKit r ...
- 腾讯云,搭建Git服务器
下载安装 git 任务时间:5min ~ 10min Git 是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. 此实验以 CentOS 7.2 x64 的系统为环境,搭建 ...
- ACM多校联赛7 2018 Multi-University Training Contest 7 1009 Tree
[题意概述] 给一棵以1为根的树,树上的每个节点有一个ai值,代表它可以传送到自己的ai倍祖先,如果不存在则传送出这棵树.现在询问某个节点传送出这棵树需要多少步. [题解] 其实是把“弹飞绵羊”那道题 ...
- codeforces 689 Mike and Shortcuts(最短路)
codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路 ...
- pace.js – 网页自动加载进度条插件
网站顶部的页面加载进度条是怎么实现的,页面的加载进度百分比,有时候获取是比较麻烦的,当然也可以利用一些优秀的JavaScript插件来实现,今天就为大家介绍这样子的一款插件:pace.js. [官方网 ...
- HTTP Simple Storage
ubuntu12.10桌面版 1.安装FastCGI /usr/bin/spawn-fcgi这个文件来管理 FastCGI,它原属于lighttpd这个包里面,但 9.10 后,spawn-fcgi被 ...
- BZOJ5089: 最大连续子段和
维护一个序列支持以下操作:区间加,区间求最大子段和.n<=50000,m<=50000. 我TM再也不写分块了... 先分块,对于块整体加的操作,假设块里面有若干二元组(x,y),表示一个 ...