Naive Operations HDU多校(线段树上线段果)
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for a
2. query l r: query ∑r
i=l
⌊a
i
/b
i
⌋
For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.
In the second line, n integers separated by spaces, representing permutation b.
In the following q lines, each line is either in the form 'add l r' or 'query l r', representing an operation.
1≤n,q≤100000
, 1≤l≤r≤n
, there're no more than 5 test cases.
1 5 2 4 3
add 1 4
query 1 4
add 2 5
query 2 5
add 3 5
query 1 5
add 2 4
query 1 4
add 2 5
query 2 5
add 2 2
query 1 5
1
2
4
4
6
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + ;
int n,m,a[maxn];
struct node {
LL val, key, lazy, sum;
} tree[maxn << ];
void pushup(int rt) {
tree[rt].sum = tree[rt << ].sum + tree[rt << | ].sum;
tree[rt].val = min(tree[rt << ].val, tree[rt << | ].val);
}
void pushdown(int rt) {
tree[rt << ].lazy += tree[rt].lazy;
tree[rt << | ].lazy += tree[rt].lazy;
tree[rt << ].val -= tree[rt].lazy;
tree[rt << | ].val -= tree[rt].lazy;
tree[rt].lazy = ;
}
void build(int l, int r, int rt) {
tree[rt].lazy = tree[rt].sum = ;
if (l == r) {
tree[rt].key = tree[rt].val = a[l];
return ;
}
int m = (l + r) >> ;
build(l, m, rt << );
build(m + , r, rt << | );
pushup(rt);
}
void update(int L, int R, int l, int r, int rt) {
if(l > r) return ;
if (tree[rt].val > && l == L && r == R) {
tree[rt].val--;
tree[rt].lazy++;
return ;
}
if (tree[rt].val == && l == r) {
tree[rt].sum++;
tree[rt].val = tree[rt].key;
tree[rt].lazy = ;
return ;
}
if (tree[rt].lazy > ) pushdown(rt);
int m = (l + r) >> ;
if (R <= m) update(L, R, l, m, rt << );
else if (L > m) update(L, R, m + , r, rt << | );
else {
update(L, m, l, m, rt << );
update(m + , R, m + , r, rt << | );
}
pushup(rt);
}
LL query(int L, int R, int l, int r, int rt) {
if(l > r) return ;
if (l == L && r == R) return tree[rt].sum;
int m = (l + r) >> ;
if (R <= m) return query(L, R, l, m, rt << );
else if (L > m) return query(L, R, m + , r, rt << | );
else return query(L, m, l, m, rt << ) + query(m + , R, m + , r, rt << | );
}
int main() {
while(scanf("%d%d", &n, &m) != EOF) {
for (int i = ; i <= n ; i++ ) scanf("%d", &a[i]);
build(, n, );
char str[];
int x, y;
while(m--) {
scanf("%s%d%d", str, &x, &y);
if (str[] == 'a') update(x, y, , n, );
else printf("%lld\n", query(x, y, , n, ));
}
}
return ;
}
Naive Operations HDU多校(线段树上线段果)的更多相关文章
- HDU6315 Naive Operations(多校第二场1007)(线段树)
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU-6315 Naive Operations//2018 Multi-University Training Contest 2___1007 (线段树,区间除法)
原题地址 Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/ ...
- CodeForces121E 线段树上线段果
http://codeforces.com/problemset/problem/121/E 题意: Petya 喜欢幸运数,幸运数只包含 4 和 7 这两个数字.例如 47,744,4 都是幸运数字 ...
- HDU6602 Longest Subarray hdu多校第二场 线段树
HDU6602 Longest Subarray 线段树 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6602 题意: 给你一段区间,让你求最长的区间使 ...
- 杭电多校第二场 hdu 6315 Naive Operations 线段树变形
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU 6351 Naive Operations(线段树)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=6315 Naive Operations Time Limit: 6000/3000 MS (Java/O ...
- hdu Naive Operations 线段树
题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...
- HDU 多校对抗 F Naive Operations
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- hdu 5930 GCD 线段树上二分/ 强行合并维护信息
from NOIP2016模拟题28 题目大意 n个点的序列,权值\(<=10^6\) q个操作 1.单点修改 2.求所有区间gcd中,不同数个数 分析 1.以一个点为端点,向左或向右的gcd种 ...
随机推荐
- 165. Merge Two Sorted Lists【LintCode by java】
Description Merge two sorted (ascending) linked lists and return it as a new sorted list. The new so ...
- MarkDown编辑器使用
有几款好用的MarkDown编辑器,参考: https://blog.csdn.net/bat67/article/details/72804251 我就下载的是 MarkDown 2来使用. 现用现 ...
- Memcache的客户端连接系列(一) Java
声明:本文并非原创,转自华为云帮助中心的分布式缓存服务(Memcached)的用户指南. 关键词: Memcached 客户端 Java Java连接池 Java客户端示例 用户的弹性云服务器已安装 ...
- CryptoZombies学习笔记——Lesson4
第四课主要介绍payable函数相关. chapter1: payable修饰函数 以太坊允许同时调用函数和eth转账.msg.value显示发送到合约的以太币数,ether是内置整型数.如果函数没有 ...
- BZOJ 3166 HEOI2013 ALO 可持久化trie+st表
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3166(洛谷上也有) 题意概述: 给出一个序列,对于一个区间,其权值为区间中的次大值亦或区 ...
- “Hello world!”团队—选题展示
本次选题展示内容: 一.视频展示 链接:http://v.youku.com/v_show/id_XMzA5Mzk5NjYwOA==.html?sharefrom=iphone 视频截图链接:http ...
- Thunder团队第五周 - Scrum会议7
Scrum会议7 小组名称:Thunder 项目名称:i阅app Scrum Master:苗威 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传康 ...
- Swift as as!和as?的区别
1.as的使用场合 1.从派生类转换为基类,向上转类型(upcasting) class Animal{} class Dog:Animal{} let cat = ANimal() let dog ...
- 第四章 持续集成jenkins工具使用之项目配置
1.1 创建项目 点击“新建”,输入项目名称,选择“构建一个自由风格的软件项目”,点击ok,项目创建完成. 1.2 配置项目 点击步骤1创建的项目,进入项目页面,如图: 点击“配置”,进入配置 ...
- asp.net MVC4 @Html.DropDownList的使用
在MVC4中使用Razor语法,一使用就爱上他了, 一般项目都是有一些增删改查功能,表单下拉框是经常使用的,除了用原始的<select>外,还可以用@Html.DropDownList和@ ...