北京师范大学第十七届程序设计竞赛决赛 G
传送门:https://ac.nowcoder.com/acm/contest/895/G
题意:
Ai=min(Ai,(i−L)×Y+X)Ai=min(Ai,(i−L)×Y+X),\\
其中 L, R, X, Y 均为整数,且有 1≤L≤R≤n,|X|≤100000,|Y|≤5\\
操作 2:x,询问Ax的值,这里 x 是整数,且有1≤x≤n
\]
题解:
如果我们区间更新最小值的话,这个min值将变的十分难以维护,所以我们考虑将公式拆分出来
由于单点查询时我们枚举出了Y,所以我们只需要维护x-L*Y这个值
\]
我们发现,每次更新时,实际上我们查询到的答案只与原先的ai以及修改后的min [y] [pos]有关,所以我们维护一个关于y的线段树,考虑到y的数据范围只有-5~5,我们开十一颗线段树,维护每一个y值时的当前区间的最小值即可,Min[y][rt]代表Y值为y时,当前区间的最小值是多少;
由于y*i可以在后面枚举y的时候消掉,所以我们每次就只需要区间维护min(Min[y][rt],X-L*y)这个值,后面查询的时候加上单点位置pos*y即可
代码:
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
// warm heart, wagging tail,and a smile just for you!
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// 佛祖保佑 永无BUG
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
void build(int num[], int l, int r, int rt) {
num[rt] = INF;
if(l == r) return;
int mid = (l + r) >> 1;
build(num,lson);
build(num,rson);
}
void update(int L, int R, int val, int num[], int l, int r, int rt) {
if(L <= l && r <= R) {
num[rt] = min(num[rt], val);
return;
}
int mid = (l + r) >> 1;
if(L <= mid) update(L, R, val, num, lson);
if(R > mid) update(L, R, val, num, rson);
}
int query(int pos, int num[], int l, int r, int rt) {
if(l == r) {
return num[rt];
}
int mid = (l + r) >> 1;
if(pos <= mid) return min(num[rt], query(pos, num, lson));
else return min(num[rt], query(pos, num, rson));
}
int num[12][maxn << 2];
int a[maxn];
int main() {
#ifndef ONLINE_JUDGE
FIN
#endif
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for(int i = 0; i <= 10; i++) {
build(num[i], 1, n, 1);
}
while(m--) {
int op;
scanf("%d", &op);
if(op == 1) {
int L, R, X, Y;
scanf("%d%d%d%d", &L, &R, &X, &Y);
int val = (-L * Y + X);
update(L, R, val, num[Y + 5], 1, n, 1);
} else {
int pos;
scanf("%d", &pos);
int ans = a[pos];
for(int y = 0; y <= 10; y++) {
ans = min(ans, (y - 5) * pos + query(pos, num[y], 1, n, 1));
}
printf("%d\n", ans);
}
}
return 0;
}
北京师范大学第十七届程序设计竞赛决赛 G的更多相关文章
- 北京师范大学第十六届程序设计竞赛决赛 I 如何办好比赛
链接:https://www.nowcoder.com/acm/contest/117/I来源:牛客网 如何办好比赛 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他 ...
- 北京师范大学第十六届程序设计竞赛决赛-重现赛-B题
一.题目链接 https://www.nowcoder.com/acm/contest/117/B 二.题意 给定一组序列$a_1,a_2,\cdots,a_n$,表示初始序列$b_1,b_2,\cd ...
- 北京师范大学第十六届程序设计竞赛决赛 F 汤圆防漏理论
链接:https://www.nowcoder.com/acm/contest/117/F来源:牛客网 汤圆防漏理论 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他 ...
- 北京师范大学第十六届程序设计竞赛决赛 C萌萌哒身高差
链接:https://www.nowcoder.com/acm/contest/117/C来源:牛客网 萌萌哒身高差 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他 ...
- 陕西师范大学第七届程序设计竞赛网络同步赛 I 排队排队排队【数组任一位可以移动到队头,最少移动几次增序/数组指针操作】
链接:https://www.nowcoder.com/acm/contest/121/I来源:牛客网 题目描述 ACM竞赛队内要开运动会啦!!!! 竞赛队内的一群阳光乐观积极的队员们迅速的在操场上站 ...
- 哈尔滨理工大学第七届程序设计竞赛决赛(网络赛-高年级组)I - 没有名字
题目描述 tabris实在是太菜了,没打败恶龙,在绿岛也只捡到一块生铁回去了,为了不在继续拉低acimo星球的平均水平逃离地球,来到了Sabi星球. 在这里tabris发现了一种神奇的生物,这种生物不 ...
- 陕西师范大学第七届程序设计竞赛网络同步赛 J 黑猫的小老弟【数论/法拉数列/欧拉函数】
链接:https://www.nowcoder.com/acm/contest/121/J来源:牛客网 题目描述 大家知道,黑猫有很多的迷弟迷妹,当然也有相亲相爱的基友,这其中就有一些二五仔是黑猫的小 ...
- 陕西师范大学第七届程序设计竞赛网络同步赛D ZQ的睡前故事【约瑟夫环1-N数到第k个出队,输出出队顺序/ STL模拟】
链接:https://www.nowcoder.com/acm/contest/121/D来源:牛客网 题目描述 ZQ是一个拥有n女朋友的万人迷,她的每一个女朋友每天晚上都会挨个给他打电话,要他讲了睡 ...
- 陕西师范大学第七届程序设计竞赛网络同步赛 C iko和她的糖【贪心/ STL-优先队列/ 从1-N每个点有能量补充,每段有消耗,选三个点剩下最多能量】
链接:https://www.nowcoder.com/acm/contest/121/C来源:牛客网 题目描述 iko超级超级喜欢吃糖,有一天iko想出去玩,她计划从1点走到N点(按1,2,3,.. ...
随机推荐
- Minimum Depth of Binary Tree最短深度
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- 洛谷P4126 [AHOI2009]最小割
题目:洛谷P4126 [AHOI2009]最小割 思路: 结论题 在残余网络上跑tarjan求出所有SCC,记id[u]为点u所在SCC的编号.显然有id[s]!=id[t](否则s到t有通路,能继续 ...
- [Java]ITOO初步了解 标签: javajbosstomcat 2016-05-29 21:14 3367人阅读 评论(34)
开始接触Java的ITOO了,这两天在搭环境,结果发现,哇,好多没接触过的东西,先写篇博客来熟悉一下这些工具. JBoss 基于Tomcat内核,青胜于蓝 Tomcat 服务器是一个免费的开放 ...
- C++结构体中的静态变量
分享一个挺有意思的代码: #include <bits/stdc++.h> using namespace std; struct Point { static int cnt; Poin ...
- 2018-9-30-VisualStudio-使用多个环境进行调试
title author date CreateTime categories VisualStudio 使用多个环境进行调试 lindexi 2018-09-30 18:39:26 +0800 20 ...
- C#判断文件是否被混淆
可以使用混淆工具对一个DLL 和 exe 进行混淆. 但是如何知道一个文件是否已经混淆了. 在发布之前,需要知道是不是有文件忘了混淆. 要判断文件是否混淆,必须知道常用的混淆手法. 混淆就是因为编写的 ...
- golang gin框架 使用swagger生成api文档
github地址:https://github.com/swaggo/gin-swagger 1.下载swag $ go get -u github.com/swaggo/swag/cmd/swag ...
- 请注意更新TensorFlow 2.0的旧代码
TensorFlow 2.0 将包含许多 API 变更,例如,对参数进行重新排序.重新命名符号和更改参数的默认值.手动执行所有这些变更不仅枯燥乏味,而且容易出错.为简化变更过程并让您尽可能顺畅地过渡到 ...
- C++中文本的读入
读入文本文件 标准库包含逐行读取文本文件的功能.然后,你可以一次一行地解析文本文件的每一行. 比如说,你有文件,其中使用数字和逗号表示一个 3x4 的矩阵: , , , 10.5 , , , , , ...
- 解决bootStrap selectpicker 下拉栏上方弹出
最近项目中遇到了一个使用bootStrap selectpicker 进行下拉栏展示的时候出现在元素上方弹出展示的问题,可把我难受坏了,和测试互怼最终以失败告终(人家还是一个娇滴滴的小姑娘),在查了a ...