“玲珑杯”ACM比赛 Round #19
Time Limit:2s Memory Limit:128MByte
Submissions:1599Solved:270
You have a sequence anan, which satisfies:

Now you should find the value of ⌊10an⌋⌊10an⌋.
#include <stdio.h>
#include <math.h>
int pow10(int i){
int ans=;
for(int j=;j<i;j++)
ans*=;
return ans;
}
int main(){
int n;
while(~scanf("%d",&n)){
int ans=n+(int)log10(n*1.0);
if(n==)ans-=;
for(int i=;i<=;i++){
int x=pow10(i);
if(x+-i<n&&n<x)
ans++;
}
printf("%d\n",ans);
}
return ;}
Time Limit:2s Memory Limit:128MByte
Submissions:699Solved:186
There are nn buildings lined up, and the height of the ii-th house is hihi.
An inteval [l,r][l,r](l≤r)(l≤r) is harmonious if and only if max(hl,…,hr)−min(hl,…,hr)≤kmax(hl,…,hr)−min(hl,…,hr)≤k.
Now you need to calculate the number of harmonious intevals.
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxN = 2e5+;
int n, k, a[maxN];
LL ans;
void input() {
scanf("%d%d", &n, &k);
for (int i = ; i < n; ++i)
scanf("%d", &a[i]);
}
void work() {
ans = ;
deque<int> mi, ma;
int p = ;
for (int i = ; i < n; ++i) {
while (!(mi.empty() && ma.empty()) &&
!(abs(a[i]-a[mi.front()]) <= k && abs(a[i]-a[ma.front()]) <= k)) {
p++;
while (!mi.empty() && mi.front() < p)
mi.pop_front();
while (!ma.empty() && ma.front() < p)
ma.pop_front();
}
ans += i-p+;
while (!mi.empty() && a[mi.back()] > a[i])
mi.pop_back();
mi.push_back(i);
while (!ma.empty() && a[ma.back()] < a[i])
ma.pop_back();
ma.push_back(i);
}
printf("%lld\n", ans);
} int main() {
input();
work();
return ;
}
ST表
void rmqinit()
{
for(int i = ; i <= n; i++) mi[i][] = mx[i][] = w[i];
int m = (int)(log(n * 1.0) / log(2.0));
for(int i = ; i <= m; i++)
for(int j = ; j <= n; j++)
{
mx[j][i] = mx[j][i - ];
if(j + ( << (i - )) <= n) mx[j][i] = max(mx[j][i], mx[j + ( << (i - ))][i - ]);
mi[j][i] = mi[j][i - ];
if(j + ( << (i - )) <= n) mi[j][i] = min(mi[j][i], mi[j + ( << (i - ))][i - ]);
}
}
int rmqmin(int l,int r)
{
int m = (int)(log((r - l + ) * 1.0) / log(2.0));
return min(mi[l][m] , mi[r - ( << m) + ][m]);
}
int rmqmax(int l,int r)
{
int m = (int)(log((r - l + ) * 1.0) / log(2.0));
return max(mx[l][m] , mx[r - ( << m) + ][m]);
}
“玲珑杯”ACM比赛 Round #19的更多相关文章
- “玲珑杯”ACM比赛 Round #19题解&源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】
A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...
- “玲珑杯”ACM比赛 Round #19 B -- Buildings (RMQ + 二分)
“玲珑杯”ACM比赛 Round #19 Start Time:2017-07-29 14:00:00 End Time:2017-07-29 16:30:00 Refresh Time:2017-0 ...
- lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP
E -- Expected value of the expression DESCRIPTION You are given an expression: A0O1A1O2A2⋯OnAnA0O1A1 ...
- 玲珑杯”ACM比赛 Round #19 B 维护单调栈
1149 - Buildings Time Limit:2s Memory Limit:128MByte Submissions:588Solved:151 DESCRIPTION There are ...
- “玲珑杯”ACM比赛 Round #1
Start Time:2016-08-20 13:00:00 End Time:2016-08-20 18:00:00 Refresh Time:2017-11-12 19:51:52 Public ...
- “玲珑杯”ACM比赛 Round #12题解&源码
我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧! A ...
- “玲珑杯”ACM比赛 Round #18
“玲珑杯”ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time ...
- “玲珑杯”ACM比赛 Round #1 题解
A:DESCRIPTION Eric has an array of integers a1,a2,...,ana1,a2,...,an. Every time, he can choose a co ...
- 玲珑杯”ACM比赛 Round #4 1054 - String cut 暴力。学到了扫描的另一种思想
http://www.ifrog.cc/acm/problem/1054 问删除一个字符后的最小循环节是多少. 比赛的时候想不出,不知道怎么暴力. 赛后看了别人代码才晓得.唉,还以为自己字符串还不错, ...
随机推荐
- Flask 学习系列(二)---Jinjia2模板
下面是一个jinjia2的简单模板的例子: <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- AJPFX关于子类父类中的构造
1.子父类中的构造函数不存在重写,因为子父类的构造函数名字不一样(重写要求子父类的方法名字一模一样,包括参数列表)2.子类创建对象时会先运行父类的构造函数再运行子类的构造函数.因为每个子类的构造函数的 ...
- [BZOJ2982]combination Lucas定理
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2982 $C(N,M)\% P = C(N\% P,M\% P) * C(N/P,M/P)\ ...
- arcgis jsapi接口入门系列(10):图形高亮
jsapi也有提供高亮的实现接口,但这里没用,而用的是一种改变图形(graphic)样式的思路 本文实现效果是:地图有多个面图形,当鼠标移动到面的上方,面高亮显示,鼠标移出后高亮解除 初始化 //高亮 ...
- 详解ASP.NET缓存机制
文中对ASP.NET的缓存机制进行了简述,ASP.NET中的缓存极大的简化了开发人员的使用,如果使用得当,程序性能会有客观的提升.缓存是在内存存储数据的一项技术,也是ASP.NET中提供的重要特性之一 ...
- OpenCV中CvMat的初始化[转]
一)cvCreateMat创建和分配数据CvCreateMat会创建CvMat,并为CvMat分配数据.cvCreateMat可以配合cvInitMatHeader来初始化CvMat对象.因为CvCr ...
- 【Web应用】JAVA网络上传大文件报500错误
问题描述 当通过 JAVA 网站上传大文件,会报 500 错误. 问题分析 因为 Azure 的 Java 网站都是基于 IIS 转发的,所以我们需要关注 IIS 的文件上传限制以及 requestT ...
- 查看进程lsof
查看8000端口 lsof -i :8000 杀死进程 pkill -ns <pid>
- 产生式模型(生成式模型)与判别式模型<转载>
转自http://dongzipnf.blog.sohu.com/189983746.html 产生式模型与判别式模型 产生式模型(Generative Model)与判别式模型(Discrimiti ...
- A. Pride (emmmm练习特判的好题)
题目连接 : http://codeforces.com/problemset/problem/891/A You have an array a with length n, you can per ...