codevs5037 线段树练习4加强版(暴力分块)
求大爷教线段树怎么写啊QAQ
只会写分块...一开始脑抽写成了O(NKlogN)还被CZL大爷嘲讽了一发T T
f[i][j]表示在第i块中,模k为j的数有几个,然后每次修改的时候只需要打个标记,查询的时候直接加上标记查就行了
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=;
int n,m,k,blo,x,y,z;
int a[maxn],bl[maxn],blcnt[][maxn],bl2[maxn],bltag[maxn],bltag2[maxn];
char s[];
inline void read(int &k)
{
int f=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',c=getchar();
k*=f;
}
#define update(x) x>=k&&(x-=k)
inline void change(int x,const int &delta)
{
int now=a[x];
blcnt[bl[x]][now]--;
now+=delta;update(now);
blcnt[bl[x]][now]++;
a[x]+=delta;update(a[x]);
}
inline void add(int l,int r,const int &delta)
{
for(int i=l;i<=min(r,bl[l]*blo);i++)change(i,delta);
if(bl[l]!=bl[r])for(int i=(bl[r]-)*blo+;i<=r;i++)change(i,delta);
for(int i=bl[l]+;i<bl[r];i++)
{
bltag[i]+=delta;update(bltag[i]);
bltag2[i]-=delta;bltag2[i]<&&(bltag2[i]+=k);
}
}
inline int min(int a,int b){return a<b?a:b;}
int query(int l,int r)
{
int ans=,tmp,mn=min(bl[l]*blo,r);
for(int i=l;i<=mn;i++)
ans+=((tmp=a[i]+bltag[bl[i]])==k||!tmp);
if(bl[l]!=bl[r])for(int i=(bl[r]-)*blo+;i<=r;i++)
ans+=((tmp=a[i]+bltag[bl[i]])==k||!tmp);
for(int i=bl[l]+;i<bl[r];i++)ans+=blcnt[i][bltag2[i]];
return ans;
}
int main()
{
read(n);read(m);read(k);blo=sqrt(n);
for(int i=;i<=n;i++)bl[i]=(i-)/blo+;
for(int i=;i<=n;i++)read(x),a[i]=x%k;
for(int i=;i<=n;i++)blcnt[bl[i]][a[i]]++;
for(int i=;i<=m;i++)
{
scanf("%s",s);read(x);read(y);
if(s[]=='a')
{
read(z);z%=k;
z<&&(z+=k);
add(x,y,z);
}
else printf("%d\n",query(x,y));
}
}
codevs5037 线段树练习4加强版(暴力分块)的更多相关文章
- 分块试水--CODEVS5037 线段树练习4加强版
感觉这才算入门题吧..前面那些线段树练习,改几个字符就过了一定要搞成几道题.. n<=2e5的数列,给常数K<=2e5,m<=2e5个操作,区间加,问一个区间里K的倍数. 这题空间? ...
- Codeves-5037线段树4加强版(线段树? 。。。分块)
维护一个序列,要求支持下列2种操作: add a b c:区间[a,b]中每个数加上c count a b:查询区间[a,b]中有多少数是k的倍数(k为给定常数) 输入描述 Input Descrip ...
- CODEVS.5037.线段树练习4加强版(分块 区间k的倍数)
题目链接 /* 如果用线段树,每个节点要再开k的空间,显然不行.但是分块可以(虽然空间依旧爆炸) 分块.用bloans[i][j]表示 第i块 模k为j 的有多少个 对于不是整块的,查询时应判断 A[ ...
- HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)
http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...
- HDU4288:Coder(线段树单点更新版 && 暴力版)
Problem Description In mathematics and computer science, an algorithm describes a set of procedures ...
- HDU 1394 逆序数 线段树单点跟新 | 暴力
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- TZOJ 4325 RMQ with Shifts(线段树查询最小,暴力更新)
描述 In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each que ...
- 线段树专题2-(加强版线段树-可持续化线段树)主席树 orz! ------用于解决区间第k大的问题----xdoj-1216
poj-2104(区间第K大问题) #include <iostream> #include <algorithm> #include <cstdio> #incl ...
- hdu 4288 线段树 暴力 **
题意: 维护一个有序数列{An},有三种操作: 1.添加一个元素. 2.删除一个元素. 3.求数列中下标%5 = 3的值的和. 解题思路: 看的各种题解,今天终于弄懂了. 由于线段树中不支持添加.删除 ...
随机推荐
- 「Python」Convert map object to numpy array in python 3
转自Stackoverflow.备忘用. Question In Python 2 I could do the following: import numpy as np f = lambda x: ...
- [wirtting] top01 independent
Do you agree or disagree with the following statement? At universities and colleges, sports and soci ...
- Java中二进制数与整型之间的转换
import java.io.*; public class Test{ /** * 二进制与整型之间的转换 * @param args * @throws IOException */ public ...
- TensorFlow入门之MNIST最佳实践-深度学习
在上一篇<TensorFlow入门之MNIST样例代码分析>中,我们讲解了如果来用一个三层全连接网络实现手写数字识别.但是在实际运用中我们需要更有效率,更加灵活的代码.在TensorFlo ...
- anaconda安装scrapy报错解决办法
今天在用anaconda安装scrapy的时候遇见个坑,现在将解决办法发出来,供大家参考使用: 问题描述: anaconda安装scrapy,使用 conda install scrapy 命令.安装 ...
- UVALive 3668 A Funny Stone Game(博弈)
Description The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2,..., ...
- 小程序之web-view打开外部链接
小程序之web-view - 传送门 web-view 组件是一个可以用来承载网页的容器,会自动铺满整个小程序页面.个人类型与海外类型的小程序暂不支持使用. 一:小程序使用web-view打开链接的前 ...
- python学习摘要(3)--字符串处理函数
python没有字符类型, "字符串" '字符串' '''字符串''' """字符串""" 三引号可以支持字符串跨行 字 ...
- 刷ROM必備的clockworkmod recovery
Desire HD 手機早早就 Root,前陣子也S-OFF 變成工程版的 HBOOT(ENG S-OFF),想要刷機的朋友一定常常聽人提起 clockworkmod recovery ,接下來就是安 ...
- TCP系列18—重传—8、FACK及SACK reneging下的重传
一.介绍 FACK的全称是forward acknowledgement,FACK通过记录SACK块中系列号最大(forward-most)的SACK块来推测丢包信息,在linux中使用fackets ...