https://www.luogu.org/problemnew/show/P3372

#include<bits/stdc++.h>
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pqueue priority_queue
#define NEW(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x&(-x))
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define lc (d<<1)
#define rc (d<<1|1)
const double pi=4.0*atan(1.0);
const double e=exp(1.0);
const int maxn=1e5+;
typedef long long LL;
typedef unsigned long long ULL;
const LL mod=1e9+;
const ULL base=1e7+;
using namespace std;
struct node{
int type,x,st;
LL v;
bool operator<(const node &t) const{
return x==t.x?type<t.type:x<t.x;
}
}q[maxn<<],temp[maxn<<];
LL ans[maxn];
LL pre[maxn];
void cdq(int l,int r){
if(l==r) return ;
//cout<<l<<' '<<r<<endl;
int mid=(l+r)>>;
cdq(l,mid);cdq(mid+,r);
int i=l,j=mid+,p=l;
LL now=,val=;
int last=;
while(i<=mid||j<=r){
if(j>r||(i<=mid&&q[i]<q[j]) ){
now+=(q[i].x-last)*val; last=q[i].x;
if(q[i].type==) val+=q[i].v;
temp[p++]=q[i++];
}
else{
now+=(q[j].x-last)*val; last=q[j].x;
if(q[j].type==) ans[q[j].st]+= now*q[j].v;
temp[p++]=q[j++];
}
}
for(int i=l;i<=r;i++) q[i]=temp[i];
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
LL xx;
for(int i=;i<=n;i++){
scanf("%lld",&xx);
pre[i]=pre[i-]+xx;
}
int opt,x,y;
int st=;
int tot=;
LL v;
for(int i=;i<=m;i++){
scanf("%d",&opt);
if(opt==){
scanf("%d%d%lld",&x,&y,&v);
q[++tot].x=x-;q[tot].v=v;q[tot].type=;
q[++tot].x=y;q[tot].v=-v;q[tot].type=;
}
else{
scanf("%d%d",&x,&y);
++st;
ans[st]=pre[y]-pre[x-];
q[++tot].x=x-;q[tot].v=-;q[tot].type=;q[tot].st=st;
q[++tot].x=y;q[tot].v=;q[tot].type=;q[tot].st=st;
}
}
cdq(,tot);
for(int i=;i<=st;i++) printf("%lld\n",ans[i]);
}

最新文章

  1. IDEA开发多项目的示例
  2. Sublime Text3快捷键汇总
  3. php中pdo例子
  4. 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)
  5. 查看Linus中自带的jdk ,设置JAVA_HOME
  6. 如何进行shell脚本正确性测试
  7. Socket异步通信学习二
  8. POJ 2923 Relocation
  9. Direct2D 几何计算和几何变幻
  10. HTML5 的WebSocket
  11. 闲聊select和input常用的小插件
  12. JAVA基础面试(四)
  13. ASP.NET MVC4通过UrlRewriter配置伪静态,支持html后缀
  14. 解决apache httpd列出目录列表中文乱码问题
  15. C风格字符串和C++string对象的相互转化
  16. 【Tomcat】Unrecognized Windows Sockets error: 10106: Socket creation failed
  17. Xcode调试LLDB
  18. Scrutiny of Partner&#39;s individual project Code
  19. document的全量替换、强制创建、删除
  20. java日志及异常错误信息输出的问题

热门文章

  1. CentOS 7.x 如何关闭 numa
  2. 多个ROS工作空间常见的问题
  3. securecrt 方向键乱码解决
  4. (转)Android之发送短信的两种方式
  5. 利用MYSQL的函数实现用户登录功能,进出都是JSON(第二版)
  6. golang 结构体中的匿名接口
  7. PHP 实现多网站共享用户SESSION 数据解决方案
  8. 数据传输流程和socket简单操作
  9. 如何解决button,a,input标签自带蓝色边框
  10. 爬虫之urllib