题解:分块

解题报告:

是个板子题呢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. ubuntu MySQL采用apt-get install安装目录

    一). ubuntu下mysql安装布局: /usr/bin                      客户端程序和mysql_install_db /var/lib/mysql            ...

  2. vuex - 学习日记

    一.简单理解 简单说vuex,就是用来管理组件状态的数据,并且能在你可掌控的范围下增删改查这些数据. store容器 , state状态 二者关系(包含): 以前我也把vuex里边的state看成是一 ...

  3. Android 逆向工具

    逆向分析工具 https://github.com/skylot/jadx/ https://github.com/google/android-classyshark https://github. ...

  4. ngnix +tomcat7 简单配置

    1.下载tomcat7 修改conf 文件夹下的server.xml文件 1.<Server port="8205" shutdown="SHUTDOWN" ...

  5. Linux上VNC 启动和关闭常见问题

    0, 重设密码 [root@yqrh5u2 ~]# vncpasswd           Password:          Verify:        [root@yqrh5u2 ~]# 1, ...

  6. php底层变量分析

    <?php //数组引用 $arr = array('a','b','c','d'); $x = & $arr[1]; $tmp = $arr; $arr[1] = 'e'; echo ...

  7. VUE单独页面body css设置

    使用created周期用JS来处理BODY的样式 export default { beforeCreate: function () { document.getElementsByTagName( ...

  8. 【CF815D】Karen and Cards 单调栈+扫描线

    [CF815D]Karen and Cards 题意:一张卡片有三个属性a,b,c,其上限分别为A,B,C,现在有n张卡片,定义一张卡片能打败另一张卡片当且仅当它的至少两项属性要严格大于另一张的对应属 ...

  9. iOS的socket开发基础

    目录[-] socket简介 tcp和udp的区别 TCP三次握手和四次挥手 TCP三次握手 tcp四次挥手 tcpsocket和udpsocket的具体实现 tcpsocket的具体实现 udpso ...

  10. Thinkphp框架下(同服务器下)不同二级域名之间session互通共享设置

    在Thinkphp框架下根目录打开index.php 在头部加入如下代码即可: //入口文件 define('DOMAIN','abc.com');//abc.com换成自己的跟域名 //以下两行是为 ...