Luogu2801 教主的魔法 (分块)
与hzw的分块2类似,放vector排序
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG
#ifdef ON_DEBUG
#define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin);
#else
#define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#endif
struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std;
#include <vector>
const int N = 1000007;
int n;
int block[N], blockSize;
int a[N], tag[N];
vector<int> V[1007];
inline void Reset(int x){
V[x].clear();
R(i,(x - 1) * blockSize + 1, block[x] * blockSize){
V[x].push_back(a[i]);
}
sort(V[x].begin(), V[x].end());
}
inline void Updata(int L, int R, int w){
int minn = Min(R, block[L] * blockSize);
R(i,L,minn){
a[i] += w;
}
Reset(block[L]);
if(block[L] != block[R]){
R(i, (block[R] - 1) * blockSize + 1, R){
a[i] += w;
}
Reset(block[R]);
}
R(i,block[L] + 1, block[R] - 1){
tag[i] += w;
}
}
inline int Query(int L, int R, int w){
int sum = 0;
int minn = Min(R, block[L] * blockSize);
R(i,L,minn){
sum += ((a[i] + tag[block[i]]) >= w);
}
if(block[L] != block[R]){
R(i, (block[R] - 1) * blockSize + 1, R){
sum += ((a[i] + tag[block[i]]) >= w);
}
}
R(i,block[L] + 1, block[R] - 1){
sum += blockSize - (lower_bound(V[i].begin(), V[i].end(), w - tag[i]) - V[i].begin());
}
return sum;
}
int main(){
int m;
io >> n >> m;
blockSize = sqrt(n);
R(i,1,n){
io >> a[i];
block[i] = (i - 1) / blockSize + 1;
V[block[i]].push_back(a[i]);
}
int cnt = n / blockSize + 1;
R(i,1,cnt)
sort(V[i].begin(), V[i].end());
while(m--){
char opt;
int L, R, w;
cin >> opt;
io >> L >> R >> w;
if(opt == 'M'){
Updata(L, R, w);
}
else{
printf("%d\n", Query(L, R, w));
}
}
return 0;
}
Luogu2801 教主的魔法 (分块)的更多相关文章
- Luogu 2801 教主的魔法 | 分块模板题
Luogu 2801 教主的魔法 | 分块模板题 我犯的错误: 有一处l打成了1,还看不出来-- 缩小块大小De完bug后忘了把块大小改回去就提交--还以为自己一定能A了-- #include < ...
- BZOJ 3343: 教主的魔法(分块+二分查找)
BZOJ 3343: 教主的魔法(分块+二分查找) 3343: 教主的魔法 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1172 Solved: ...
- BZOJ 3343: 教主的魔法 [分块]【学习笔记】
3343: 教主的魔法 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1172 Solved: 526[Submit][Status][Discus ...
- 【BZOJ-3343】教主的魔法 分块
3343: 教主的魔法 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 950 Solved: 414[Submit][Status][Discuss ...
- 【BZOJ3343】教主的魔法 分块+二分
Description 教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息组每个英雄看.于是N个英雄们又一次聚集在了一起,这次他们排成了一列,被编号为1.2.…….N. 每个人的 ...
- BZOJ3343: 教主的魔法 分块
2016-05-28 10:27:19 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3343 比较显然的分块题,分块后块内排序,维护整块的附 ...
- 洛谷P2801 教主的魔法 [分块,二分答案]
题目传送门 教主的魔法 题目描述 教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息组每个英雄看.于是N个英雄们又一次聚集在了一起,这次他们排成了一列,被编号为1.2.…….N. ...
- Bzoj 3343: 教主的魔法(分块+二分答案)
3343: 教主的魔法 Time Limit: 10 Sec Memory Limit: 256 MB Description 教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息 ...
- 【bzoj3343】教主的魔法 分块
[bzoj3343]教主的魔法 2014年4月26日8092 Description 教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息组每个英雄看.于是N个英雄们又一次聚集在了 ...
- Bzoj 3343: 教主的魔法 分块,二分
3343: 教主的魔法 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 821 Solved: 364[Submit][Status][Discuss ...
随机推荐
- 【Azure 存储服务】Java Azure Storage SDK V12使用Endpoint连接Blob Service遇见 The Azure Storage endpoint url is malformed
问题描述 使用Azure Storage Account的共享访问签名(Share Access Signature) 生成的终结点,连接时遇见 The Azure Storage endpoint ...
- 第06组 Beta冲刺 (1/6)
目录 1.1 基本情况 1.2 冲刺概况汇报 1.郝雷明 2. 方梓涵 3.曾丽莉 4.黄少丹 5. 董翔云 6.杜筱 7.鲍凌函 8.詹鑫冰 9.曹兰英 10.吴沅静 1.3 冲刺成果展示 1.1 ...
- T1创世纪(原创)
创世纪 这是我的第一道原创题 题解: 这道题的核心算法是:加维度的最短路+贪心 状态:\(dis[i][j][t][a]\)表示在 \(t\) 时,到达 \((i,j)\) ,当前共造\(a\)只&q ...
- CF1601F Two Sorts
CF1601F Two Sorts 给定 \(n\),将 \(1\sim n\) 按照字典序排序,\(a_i\) 表示第 \(i\) 小的数,求: \[\left(\sum_{i=1}^{n} ((i ...
- Android 实现开机自启APP
原文地址:Android 实现开机自启APP - Stars-One的杂货小窝 公司有个项目,需要实现自启动的功能,本来想着是设置桌面启动器的方式去实现,但是设备是华为平板(EMUI系统),不允许设置 ...
- JavasScript打印年月日时间代码
就是Date的API,直接上代码啦. //打印中文的日期 function printChineseDateTime() { var now=new Date(); var str = now.get ...
- 6大优势、2种类型,一文吃透动态应用安全测试(DAST)
在在上篇文章中中,我们了解了 SAST 的概念.优劣和使用的工具,并在文章里提到了另一个软件安全领域里的重要技术 DAST.本文将会详细介绍 DAST 的概念.重要性及其工作原理. DAST(Dy ...
- Java集合框架(四)-HashMap
1.HashMap特点 存放的元素都是键值对(key-value),key是唯一的,value是可以重复的 存放的元素也不保证添加的顺序,即是无序的 存放的元素的键可以为null,但是只能有一个key ...
- Java判断字符串是否为金额
public static void main(String[] args) { String aa = "5632.2"; //小数点前后是数字即可,无小数点后数据也ok Sys ...
- Redis主从复制+Keepalived+VIP漂移实现HA高可用技术之详细教程
1.大家可以先看我的单台Redis安装教程,链接在此点击Redis在CentOS for LInux上安装详细教程 2.第一台redis配置,是正常配置.作为MASTER主服务器,第二台redis的配 ...