题意:对数列有三种操作:

  1. Print operation l, r. Picks should write down the value of .
  2. Modulo operation l, r, x. Picks should perform assignment a[i] = a[imod x for
    each i (l ≤ i ≤ r).
  3. Set operation k, x. Picks should set the value of a[k] to x (in
    other words perform an assignment a[k] = x).

解法:线段树更新。维护区间最大值ma和区间sum。假设訪问的x小于ma就能够忽略。否则向下更新;

代码:  
/******************************************************
* author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string.h>
//freopen ("in.txt" , "r" , stdin);
using namespace std; #define eps 1e-8
const double pi=acos(-1.0);
typedef long long LL;
const int Max=100100*2;
const int INF=1000000007;
struct node
{
int l,r;
node * left,*right;
int ma;
LL sum;
} nodes[Max];
int Mid(node* p)
{
return (p->l+p->r)/2;
}
int tot=0;
void buildtree(node* p,int left,int right)
{
p->l=left;
p->r=right;
p->ma=0;
p->sum=0;
if(left==right)
return ;
int mid=(left+right)/2;
tot++;
p->left=nodes+tot;
buildtree(p->left,left,mid);
tot++;
p->right=nodes+tot;
buildtree(p->right,mid+1,right);
}
void update(node* p,int i,int value)
{
if(p->l==i&&p->r==i)
{
p->sum=value;
p->ma=value;
return ;
}
int mid=Mid(p);
if(i<=mid)
update(p->left,i,value);
else
update(p->right,i,value);
p->sum=p->left->sum+p->right->sum;
p->ma=max(p->left->ma,p->right->ma);
}
void update2(node* p,int l,int r,int x)
{
if(p->ma<x)
return;
if(p->l==l&&p->r==r&&l==r)
{
p->sum%=x;
p->ma=p->sum;
return ;
}
int mid=Mid(p);
if(r<=mid)
update2(p->left,l,r,x);
else if(l>mid)
update2(p->right,l,r,x);
else
{
update2(p->left,l,mid,x);
update2(p->right,mid+1,r,x);
}
p->sum=p->left->sum+p->right->sum;
p->ma=max(p->left->ma,p->right->ma);
}
LL query(node* p,int l,int r)
{
if(l==p->l&&r==p->r)
{
return p->sum;
}
int mid=Mid(p);
if(r<=mid)
return query(p->left,l,r);
if(l>mid)
return query(p->right,l,r);
return query(p->left,l,mid)+query(p->right,mid+1,r);;
}
int n,m;
int main()
{
while(scanf("%d%d",&n,&m)==2)
{
tot=0;
buildtree(nodes,0,n+1);
for(int i=1; i<=n; i++)
{
int a;
scanf("%d",&a);
update(nodes,i,a);
}
while(m--)
{
int t;
scanf("%d",&t);
if(t==1)
{
int l,r;
scanf("%d%d",&l,&r);
cout<<query(nodes,l,r)<<endl;
}
else if(t==2)
{
int l,r,x;
scanf("%d%d%d",&l,&r,&x);
update2(nodes,l,r,x);
}
else if(t==3)
{
int i,x;
scanf("%d%d",&i,&x);
update(nodes,i,x);
}
}
}
return 0;
}

最新文章

  1. jquery easyui 动态绑定数据列
  2. AngularJs自定义指令详解(6) - controller、require
  3. 优化checkbox和radio,类似Bootstrap中的iCheck
  4. 使用CButtonColumn自定义CGridiew里面的按钮
  5. echarts的使用总结;
  6. FusionCharts參数中文说明
  7. extract-text-webpack-plugin 的使用及安装
  8. overflow-x: scroll;横向滑动详细讲解
  9. AngularJS 关于ng-model和ng-bind还有{{}}
  10. Django中media的配置
  11. swift函数的调用约定
  12. javascript对象的属性,方法,prototype作用范围分析.
  13. javascript消除字符串两边空格的两种方式,面向对象和函数式编程。python oop在调用时候的优点
  14. [19/05/03-星期五] GOF23_模式总结
  15. Kibana安装及简单使用
  16. js把json数据转化成树形数据
  17. windows 用户变量和系统变量的差别
  18. Samba文件共享服务器配置
  19. lead over 和 lag over
  20. koa2.0富文本编辑器的选择历程

热门文章

  1. matplotlib 可视化 —— 移动坐标轴(中心位置)
  2. 数据仓库 SSIS
  3. 使用ShareSDK分享-图片的链接
  4. python对MySQL进行添加修改删除以及字符串的操作
  5. IDEA項目配置404
  6. unbuntu禁用ipv6
  7. Chromium Graphics: Graphics and Skia
  8. oracle创建静态监听
  9. 13-Linux中进程与线程的概念以及区别
  10. 第四讲 Yang-Mills方程与Maxwell方程