北京师范大学第十七届程序设计竞赛决赛 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,.. ...
随机推荐
- 【C++】STL :栈
c++stack(堆栈)是一个容器的改编,它实现了一个先进后出的数据结构(FILO) 使用该容器时需要包含#include<stack>头文件: 定义stack对象的示例代码如下: sta ...
- @codeforces - 1209H@ Moving Walkways
目录 @description@ @solution@ @accepted code@ @details@ @description@ 机场中常常见到滑行道:假如一个滑行道的运行速度为 s,你的行走速 ...
- @bzoj - 4378@ [POI2015] Pustynia
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 n 的正整数序列 a,每个数都在 1 到 10^ ...
- hdu 3234 Exclusive-OR (并查集)
Problem - 3234 题意不难理解,就是给出一些断言,以及一些查询,回答查询或者在找到断言矛盾以后沉默不做任何事. 这题其实就是一个并查集的距离存储问题,只要记录并查集元素的相对值以及绝对值就 ...
- TP-admin即基于ThinkPHP5拿来即用高性能后台管理系统
TP-Admin即基于ThinkPHP5的web后台管理系统(总结一套自己的后台管理系统,方便自己后续的项目开发.) 主要特性:自适应手机端.支持国际化.吸取其他CMF框架优点.多站点部署.日志记录. ...
- c++第一次的个人作业
循环结构是c++中重要的结构用以实现代码的反复使用 三种不同的循环结构以及嵌套是必须认识与能够使用的 三种循环结构分别是: 在for循环中可以在for后的括号内加入初始条件,循环条件与参数变化.使得整 ...
- Codeforces Round #577 (Div 2)
A. Important Exam 水题 #include<iostream> #include<string.h> #include<algorithm> #in ...
- 得到Access数据库中所有表名
public static List<string> GetShemaTables(string db) { string pa ...
- gSOAP calc服务端与客户端示例
1. Web服务定义描述头文件 typedef double xsd__double; int ns__add(xsd__double a, xsd__double b, xsd__double &a ...
- python 字符串方法isdigit()
python isdigit() 方法检测字符串是否只有数字组成. 语法: isdigit()方法语法: str.isdigit() 参数:无 返回值: 如果字符串中只含有数字则返回True,否则返回 ...