题解:分块

解题报告:

是个板子题呢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 分块的更多相关文章

  1. 线段树---poj3468 A Simple Problem with Integers:成段增减:区间求和

    poj3468 A Simple Problem with Integers 题意:O(-1) 思路:O(-1) 线段树功能:update:成段增减 query:区间求和 Sample Input 1 ...

  2. POJ 3468 A Simple Problem with Integers(分块入门)

    题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit ...

  3. poj3468 A Simple Problem with Integers (线段树区间最大值)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92127   ...

  4. poj------(3468)A Simple Problem with Integers(区间更新)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 60745   ...

  5. POJ3468 A Simple Problem with Integers 【段树】+【成段更新】

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 57666   ...

  6. poj3468 A Simple Problem with Integers (树状数组做法)

    题目传送门 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 1 ...

  7. Poj3468 A Simple Problem with Integers (分块)

    题面 Poj 题解 区间求和\(+\)区间修改板子,这里用分块写的 #include <cmath> #include <cstdio> #include <cstrin ...

  8. POJ3468 A Simple Problem with Integers —— 线段树 区间修改

    题目链接:https://vjudge.net/problem/POJ-3468 You have N integers, A1, A2, ... , AN. You need to deal wit ...

  9. poj3468 A Simple Problem with Integers(线段树区间更新)

    https://vjudge.net/problem/POJ-3468 线段树区间更新(lazy数组)模板题 #include<iostream> #include<cstdio&g ...

随机推荐

  1. 【LeetCode OJ】Two Sum

    题目:Given an array of integers, find two numbers such that they add up to a specific target number. T ...

  2. iOS AOP编程思想及实践

    什么是 AOP Wikipedia 上的 AOP 定义: In computing, aspect-oriented programming (AOP) is a programming paradi ...

  3. django rest framwork教程之外键关系和超链接

    此时,我们的API中的关系通过使用主键来表示.在本教程的这一部分中,我们将通过使用超链接来改善关系的内聚性和可发现性 为我们的API的根创建一个端点 现在我们有"snippets" ...

  4. 二、K3 Cloud 开发插件《K3 Cloud 常用数据表整理》

    一.数据库查询常用表 --查询数据表select * from ( ),t1.FKERNELXML.query('//TableName')) as 'Item',t1.FKERNELXML,t2.F ...

  5. echarts - 特殊需求实现方案汇总

    五分钟上手echarts echarts中 设置x||y轴文案.提示文字等为固定字数,超出显示"..." 关于echarts下钻功能的一些总结.js echarts - 特殊需求实 ...

  6. How to Verify Email Address

    http://www.ruanyifeng.com/blog/2017/06/smtp-protocol.html  如何验证 Email 地址:SMTP 协议入门教程 https://en.wiki ...

  7. java(1) 编程基础

    1.classpath 环境变量 * 当java虚拟机需要运行一个类时,会在classpath 环境变量中所定义的路径下寻找所需的class文件 2.java 的基本语法 * java 语言是严格区分 ...

  8. [原]openstack-kilo--issue(二) openstack auth error

    /** 系统环境:redhat7.2 repo:163 openstack version : kilo author: lihaibo 本博客已经添加"打赏"功能,"打 ...

  9. Linux下进程隐藏的方法及其对抗

    零.背景 在应急响应中,经常碰到ps命令和top命令查不到恶意进程(异常进程)的情况,会对应急响应造成很大的影响.轻则浪费时间,重则排查不出问题,让黑客逍遥法外.所以这篇博客研究学习如何对抗linux ...

  10. Ant的Manifest任务

    建立一个清单文件,他将放入某个jar,作为jar文件的说明书.其中,在清单文件可以指定jar文件的main-class,jar文件将可以直接运行.例子: <manifest >   < ...