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的值的和. 解题思路: 看的各种题解,今天终于弄懂了. 由于线段树中不支持添加.删除 ...
随机推荐
- 「专题训练」k-Tree(CodeForces Round #247 Div.2 C)
题意与分析(Codeforces-431C) 题意是这样的:给出K-Tree--一个无限增长的树,它的每个结点都恰有\(K\)个孩子,每个节点到它\(K\)个孩子的\(K\)条边的权重各为\(1,2, ...
- 配置vConsole调试console
1.使用 npm 安装: npm install vconsole 再使用webpack,然后js代码中 import VConsole from 'vconsole/dist/vconsole.mi ...
- 国内版Office365实现MFA的方案(未完)
现在二十一世纪互联版也可以实现了MFA,现在也就是2017年3月份,支持了PC,但是对移动端应用还是不支持的,请了解. 具体方法如下: 登录国内版Office365(事例为高级商业版 https:// ...
- An Adaptive Color-Based Particle Filter--粒子滤波
粒子滤波跟踪的具体步骤如下: 1. Resampling the particles to avoid degeneracy 2. Propagate each particles accordin ...
- Fluent Python: Classmethod vs Staticmethod
Fluent Python一书9.4节比较了 Classmethod 和 Staticmethod 两个装饰器的区别: 给出的结论是一个非常有用(Classmethod), 一个不太有用(Static ...
- protected、public、private
一.protected成员 1. 受保护的成员的可访问性 对于一个类的protected成员,①该类的用户(如类对象)不能访问它,②该类的派生类的成员(及其友元)可以访问它. 派生类的成员及其友元不能 ...
- unordered_map(hash_map)和map的比较
测试代码: #include <iostream> using namespace std; #include <string> #include <windows.h& ...
- iOS- iPad里有趣的UIPopoverController
效果: 1.对UIPopoverController的简单概述 1.1 UIPopoverController是在iPad开发中常用的一个组件(在iPhone上不允许使用),使用非常简单 1.2 ...
- web前端之路 - 开篇
一 web发展历程 了解事物的历史有助于我们渐进式的从发展的思路清楚了解事物的来龙去脉. 这里有一篇网文写得比较清晰和完整:https://www.tianmaying.com/tutorial/we ...
- open-stf 安装篇(linux)
OpenSTF 百度MTC的远程真机调试 Testin的云真机 腾讯WeTest的云真机 阿里MQC的远程真机租用 什么是OpenSTF? OpenSTF是一个手机设备管理平台,可以对手机进行远 ...