题解:分块

解题报告:

是个板子题呢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. 使用Xcode自带的单元测试

    今年苹果推出的iOS8和Swift的新功能让人兴奋.同时,苹果对于Xcode的测试工具的改进却也会影响深远.现在我们来看下XCTest,Xcode内置的测试框架.以及,Xcode6新增的XCTestE ...

  2. Nginx七层反向代理和负载均衡

    1.介绍 1.1 Nginx不仅是一个出色的web软件,其七层代理和负载均衡也是相当出色.Nginx做前端代理,当用户请求服务时,可以根据url进行判断,然后分配到不同的后台webserver上. 1 ...

  3. [sql异常]SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的

    //执行远程数据库表查询 SELECT * FROM OPENDATASOURCE('SQLOLEDB', 'Data Source=数据库地址;User ID=sa;password=sa' ).n ...

  4. html2canvas - 实现网页截图(+下载截图) 功能

    实现:html2canvas + canvas.toDataURL 首先,引入依赖插件: import { html2canvas } from './html2canvas'; html2canva ...

  5. KMP算法的实现(Java语言描述)

    标签:it KMP算法是模式匹配专用算法. 它是在已知模式串的next或nextval数组的基础上执行的.如果不知道它们二者之一,就没法使用KMP算法,因此我们需要计算它们. KMP算法由两部分组成: ...

  6. 转载->C#事件的使用和讲解

    C#事件的使用和讲解 事件的由来 在上一篇幅博客中http://www.cnblogs.com/JiYF/p/6867081.html 对委托讲解的比较细致 我们继续思考上面的程序:上面的三个方法都定 ...

  7. Python pyQt4/pyQt5 学习笔记1(空白窗口,按钮,控件事件,控件提示,窗体显示到屏幕中间,messagebox)

    PyQt4是用来编写有图形界面程序(GUI applications)的一个工具包.PyQt4作为一个Python模块来使用,它有440个类和超过6000种函数和方法.同时它也是一个可以在几乎所有主流 ...

  8. IMAP命令与分析

    https://www.cnblogs.com/crystalray/p/3304688.html Internet Mail Access Protocol(缩写为IMAP,以前称作交互邮件访问协议 ...

  9. laravel blade模板里调用路由方法重定向

    @if (Session::get('user') == NULL) {!!Redirect::to('login')!!} @endif or @if (Session::get('user') = ...

  10. java(4) 异常

    1.Throwable 继承体系 * Eorro * Exception --RuntimeException 该类及其子类用于表示运行时异常,Exception类下所有其他子类都用于表示编译时异常. ...