题解:分块

解题报告:

是个板子题呢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. 【RF库Collections测试】Set List Value

    Name:Set List ValueSource:Collections <test library>Arguments:[ list_ | index | value ]Sets th ...

  2. Ansible Playbook 简介

    我们去远程执行命令时要使用 command 模块,拷贝文件时要使用 copy 模块,如果我们要操作的东西很多,那就要执行很多条不同模块的命令Playbook 是一个 yaml 配置文件,我们可以把不同 ...

  3. Memcached 命令行操作

    telnet 用于连接 Memcached: [root@localhost ~]# telnet Trying 127.0.0.1... Connected to 127.0.0.1. Escape ...

  4. Splash 简介与安装

    Splash 说白了就是一个轻量级的浏览器,利用它,我们同样可以实现跟其他浏览器一样的操作,我们使用 Docker 来安装 Splash: [root@localhost ~]# docker run ...

  5. osg内置shader变量

    uniform int osg_FrameNumber:当前OSG程序运行的帧数: uniform float osg_FrameTime:当前OSG程序的运行总时间: uniform float o ...

  6. centos6.4搭建ftp服务器

    在centos环境下搭建ftp服务器,选择用vsftpd. 1.检测是否已经安装vsftpd # rpm -qa | grep vsftpd 如果已经安装vsftpd,会显示相应版本号.没有任何提示, ...

  7. Java实现简单的正则表达式匹配

    import java.util.regex.Pattern; public class Test_REG { public static void main(String[] args) { //只 ...

  8. css笔记 - animation学习笔记(二)

    animation动画 @keyframes规则 - 创建动画 from - to 等价于 0% - 100% 但是优先使用0% - 100%,因为浏览器兼容性还好点 animation 动画绑定 将 ...

  9. 小程序判断是否授权源码 auth.js

    一.auth.js const configGlobal = require('../config/config_global.js'); var util = require('function.j ...

  10. Android 本地搭建Tomcat服务器供真机测试

    准备工具:tomcat    环境:win7 + JDK1.8 + tomcat 9.0.13(64bit) 准备工具:tomcat    1.tomcat官网下载   https://tomcat. ...