POJ3468 a simple problem with integers 分块
题解:分块
解题报告:
是个板子题呢qwq
没什么可说的,加深了对分块的理解趴还是
毕竟这么简单的板子题我居然死去活来WA了半天才调出来,,,哭了QAQ
还是说下我错在了哪几个地方(...是的,有好几个,,,太生气了太弱了!
第一个是要意识到并不是√n*(√n+1)一定>n...我我我我我卡在这儿调了半天QAQ
第二个是未满一个区间的修改的时候出来要暴力搞掉所有a[i]以外还要sum[i]+=add*len鸭!这里开始也没有想到QAQ
没了,放代码qwq
#include<iostream> #include<cmath> #include<cstring> #include<string> #include<cstdio> using namespace std; #define ll long long #define rp(i,x,y) for(register ll i=x;i<=y;++i) +,sqtN=; ll n,len,cjk,a[N],pos[N],sum[sqtN],ad[sqtN]; inline ll read() { ;; '))ch=getchar(); ; )+(x<<)+(ch^'),ch=getchar(); return y?x:-x; } inline char readch(){char ch=getchar();while(ch!='Q' && ch!='C')ch=getchar();return ch;} inline )*len+,r=min(x*len,n);rp(i,l,r)pos[i]=x,sum[x]+=a[i];ad[x]=;} inline void add(ll l,ll r,ll d) { ll x=pos[l],y=pos[r]; )*d;return;} rp(i,x+,y-)ad[i]+=d;rp(i,l,x*len)a[i]+=d;rp(i,(y-)*len+,r)a[i]+=d;sum[x]+=(x*len-l+)*d;sum[y]+=(r-(y-)*len)*d; } inline ll query(ll l,ll r) { ll x=pos[l],y=pos[r],ans=; );} rp(i,x+,y-)ans+=sum[i]+ad[i]*len;rp(i,l,x*len)ans+=a[i];rp(i,(y-)*len+,r)ans+=a[i];ans+=ad[x]*(x*len-l+)+ad[y]*(r-(y-)*len); return ans; } int main() { n=read(); ll Q=read(); cjk=len=sqrt(n);while(len*cjk<n)++cjk; rp(i,,n)a[i]=read(); rp(i,,cjk)pre(i); while(Q--) { char ch=readch(); if(ch=='Q'){ll l=read(),r=read();printf("%lld\n",query(l,r));continue;} ll l=read(),r=read(),d=read();add(l,r,d); } ; } //顺便用分块艹过了线段树嘻嘻,美滋滋qwq
POJ3468 a simple problem with integers 分块的更多相关文章
- 线段树---poj3468 A Simple Problem with Integers:成段增减:区间求和
poj3468 A Simple Problem with Integers 题意:O(-1) 思路:O(-1) 线段树功能:update:成段增减 query:区间求和 Sample Input 1 ...
- POJ 3468 A Simple Problem with Integers(分块入门)
题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit ...
- poj3468 A Simple Problem with Integers (线段树区间最大值)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92127 ...
- poj------(3468)A Simple Problem with Integers(区间更新)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 60745 ...
- POJ3468 A Simple Problem with Integers 【段树】+【成段更新】
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 57666 ...
- poj3468 A Simple Problem with Integers (树状数组做法)
题目传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 1 ...
- Poj3468 A Simple Problem with Integers (分块)
题面 Poj 题解 区间求和\(+\)区间修改板子,这里用分块写的 #include <cmath> #include <cstdio> #include <cstrin ...
- POJ3468 A Simple Problem with Integers —— 线段树 区间修改
题目链接:https://vjudge.net/problem/POJ-3468 You have N integers, A1, A2, ... , AN. You need to deal wit ...
- poj3468 A Simple Problem with Integers(线段树区间更新)
https://vjudge.net/problem/POJ-3468 线段树区间更新(lazy数组)模板题 #include<iostream> #include<cstdio&g ...
随机推荐
- 【权限维持】window服务端常见后门技术
0x00 前言 未知攻焉知防,攻击者在获取服务器权限后,通常会用一些后门技术来维持服务器权限,服务器一旦被植入后门,攻击者如入无人之境.这里整理一些window服务端常见的后门技术,了解攻击者的常见后 ...
- FTP匿名访问修复方法
window2003 window2008
- ASP代码审计学习笔记 -5.文件下载漏洞
文件下载漏洞 漏洞代码: <% function download(f,n) on error resume next Set S=CreateObject("Adodb.Stream ...
- Selenium 选项卡管理
什么是选项卡: from selenium import webdriver browser = webdriver.Chrome() browser.get("http://www.bai ...
- Streaming 101
开宗明义!本文根据Google Beam大神Tyler Akidau的系列文章<The world beyond batch: Streaming 101>(批处理之外的流式世界)整理而成 ...
- App store最新审核标准公布
本文转载至 http://blog.csdn.net/shuidonglCH/article/details/47083623 导读:苹果近日更新了App Store审核指南的相关章节,对此前版本进行 ...
- sql预计简单分页
在显示记录条目时往往要用到分页,一种常用的办法是利用各种数据库自带的定位接口对原始查询语句进行改写,从而只取出特定范围的某些记录.不同的数据库,查询定位接口是不一样的,下面做一汇总: 数据库 分页查询 ...
- 《转载》IntelliJ 2016.2 IDEA 中进行 Java Web 项目开发配置
本文转载自 https://segmentfault.com/a/1190000007088964 1. 新建一个 Web Application 项目 打开 IntelliJ,选择新建项目: 左边栏 ...
- 【架构师之路】APP架构师必看:面对爆发流量如何进行架构调整
一.APP架构与WEB架构的最大不同 移动APP的架构和传统PC的WEB架构有三点不同: 1.连接的稳定性.在传统的web端连接成功后就可以认为它是稳定的,但在移动端.无线端,APP连接非常敏感,可能 ...
- Dropbox 在 Ubuntu 上需要认证授权的问题
在 Ubuntu 上,通过 Ubuntu软件中心 搜索下载安装了 Dropbox . 运行时,弹出如下图的提示. 输入密码,点击 授权 后,没有出现 Dropbox 的运行界面. 再次点击运行,仍会出 ...