4373

思路:

  判断一个数列是否是等差数列:

    1,最大值减去最小值==(区间个数-1)*k;

    2,gcd==k;

    3,不能有重复(不会这判断这一条,但是数据水就过了);

来,上代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 300005 struct TreeNodeType {
int l, r, max, min, gcd, mid;
};
struct TreeNodeType tree[maxn << ]; int n, m, ai[maxn], ty; inline void in(int &now)
{
char Cget = getchar(); now = ;
while (Cget > '' || Cget < '') Cget = getchar();
while (Cget >= ''&&Cget <= '')
{
now = now * + Cget - '';
Cget = getchar();
}
} int gcd(int a, int b)
{
int tmp;
while(b!=) tmp=b,b=a%b,a=tmp;
return a;
} void tree_build(int now, int l, int r)
{
tree[now].l = l, tree[now].r = r;
if (l == r)
{
tree[now].gcd = ai[l] - ai[l - ];
tree[now].min = ai[l], tree[now].max = ai[l];
return;
}
tree[now].mid = l + r >> ;
tree_build(now << , l, tree[now].mid);
tree_build(now << | , tree[now].mid + , r);
tree[now].gcd = gcd(tree[now << ].gcd, tree[now << | ].gcd);
tree[now].max = max(tree[now << ].max, tree[now << | ].max);
tree[now].min = min(tree[now << ].min, tree[now << | ].min);
} void pre()
{
in(n), in(m);
for (int i = ; i <= n; i++) in(ai[i]);
tree_build(, , n);
} int tree_do(int now, int l, int r)
{
if (tree[now].l == l&&tree[now].r == r)
{
if (ty == ) return tree[now].max;
if (ty == ) return tree[now].min;
if (ty == ) return tree[now].gcd;
tree[now].gcd = ai[l] - ai[l - ];
tree[now].max = ai[l], tree[now].min = ai[l];
return ;
}
int res=;
if (l > tree[now].mid) res = tree_do(now << | , l, r);
else if (r <= tree[now].mid) res = tree_do(now << , l, r);
else
{
res = tree_do(now << , l, tree[now].mid);
if (ty == ) res = max(res, tree_do(now << | , tree[now].mid + , r));
if (ty == ) res = min(res, tree_do(now << | , tree[now].mid + , r));
if (ty == ) res = gcd(res, tree_do(now << | , tree[now].mid + , r));
}
if (ty == )
{
tree[now].gcd = gcd(tree[now << ].gcd, tree[now << | ].gcd);
tree[now].max = max(tree[now << ].max, tree[now << | ].max);
tree[now].min = min(tree[now << ].min, tree[now << | ].min);
}
return res;
} void solve()
{
int op, l, r, x, y, last = ;
for (int t = ; t <= m; t++)
{
in(op);
if (op == )
{
in(x), in(y);
x^=last,y^=last,ty=,ai[x]=y;
tree_do(,x,x);
if(x!=n) tree_do(,x+,x+);
}
else
{
in(l),in(r),in(x);
l^=last,r^=last,x^=last;
if(l==r)
{
last++;
printf("Yes\n");
continue;
}
int ma,mi,gcdd;
ty=,ma=tree_do(,l,r);
ty=,mi=tree_do(,l,r);
ty=,gcdd=tree_do(,l+,r);
if((ma-mi)==x*(r-l)&&abs(gcdd)==x) printf("Yes\n"),last++;
else printf("No\n");
}
}
} int main()
{
pre();
solve();
return ;
}

AC日记——算术天才⑨与等差数列 bzoj 4373的更多相关文章

  1. bzoj 4373 算术天才⑨与等差数列

    4373: 算术天才⑨与等差数列 Time Limit: 10 Sec  Memory Limit: 128 MBhttp://www.lydsy.com/JudgeOnline/problem.ph ...

  2. BZOJ4373 算术天才⑨与等差数列 【线段树】*

    BZOJ4373 算术天才⑨与等差数列 Description 算术天才⑨非常喜欢和等差数列玩耍. 有一天,他给了你一个长度为n的序列,其中第i个数为a[i]. 他想考考你,每次他会给出询问l,r,k ...

  3. 【BZOJ4373】算术天才⑨与等差数列 [线段树]

    算术天才⑨与等差数列 Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 算术天才⑨非常喜欢和等 ...

  4. 【BZOJ4373】算术天才⑨与等差数列 线段树+set

    [BZOJ4373]算术天才⑨与等差数列 Description 算术天才⑨非常喜欢和等差数列玩耍.有一天,他给了你一个长度为n的序列,其中第i个数为a[i].他想考考你,每次他会给出询问l,r,k, ...

  5. JSOI2009 等差数列 和 算术天才⑨与等差数列 和 CH4302 Interval GCD

    等差数列 为了检验学生的掌握情况,jyy布置了一道习题:给定一个长度为N(1≤N≤100,000)的数列,初始时第i个数为vi(vi是整数,−100,000≤vi≤100,000),学生们要按照jyy ...

  6. BZOJ 4373: 算术天才⑨与等差数列 线段树

    Description 算术天才⑨非常喜欢和等差数列玩耍. 有一天,他给了你一个长度为n的序列,其中第i个数为a[i]. 他想考考你,每次他会给出询问l,r,k,问区间[l,r]内的数从小到大排序后能 ...

  7. 【线段树 集合hash】bzoj4373: 算术天才⑨与等差数列

    hash大法好(@ARZhu):大数相乘及时取模真的是件麻烦事情 Description 算术天才⑨非常喜欢和等差数列玩耍.有一天,他给了你一个长度为n的序列,其中第i个数为a[i].他想考考你,每次 ...

  8. [线段树]洛谷P5278 算术天才⑨与等差数列

    题目描述 算术天才⑨非常喜欢和等差数列玩耍. 有一天,他给了你一个长度为n的序列,其中第i个数为a[i]. 他想考考你,每次他会给出询问l,r,k,问区间[l,r]内的数从小到大排序后能否形成公差为k ...

  9. bzoj 4373 算术天才⑨与等差数列——线段树+set

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4373 能形成公差为k的等差数列的条件:mx-mn=k*(r-l) && 差分 ...

随机推荐

  1. python-configparser模块,xml.etree模块

    操作键值对文件 #文件db格式为 [section] a = 1 b = 2 [section1] d = 3 c = 4 import configparser #获取所有节点 config = c ...

  2. ASP.NET Core [1]:Hosting(笔记)

    参考:http://www.cnblogs.com/RainingNight/p/hosting-in-asp-net-core.html

  3. ASP NET Core 部署 IIS 和发布

    1. 微软官网原文链接: https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/iis/index?view=aspnetcore- ...

  4. ironic如何支持部署时按需RAID?

    新浪大神推荐使用element proliant-tools制作deploy image.element proliant-tools会在ipa ramdisk中安装一个rpm包hpssacli(HP ...

  5. springboot11 JPA

    一.JPA 1. JPA 介绍 JPA是Java Persistence API的简称,中文名Java持久层API,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到 ...

  6. quagga源码学习--BGP协议中的routemap

    路由策略的基础知识 定义 路由策略(Routing Policy)作用于路由,主要实现了路由过滤和路由属性设置等功能,它通过改变路由属性(包括可达性)来改变网络流量所经过的路径. 目的 路由器在发布. ...

  7. Servlet 中 RequestDispacher 请求与分发

    RequestDispacher 请求与分发使用HttpServletRequest的getRequestDispatcher()方法取得 Login.java页面 package control; ...

  8. 【转载】10个最佳ES6特性

    译者按: 人生苦短,我用ES6. 原文: Top 10 ES6 Features Every Busy JavaScript Developer Must Know 译者: Fundebug 为了保证 ...

  9. 什么是SQL注入?(理解)

    SQL注入攻击是黑客对数据库进行攻击的常用手段之一.一部分程序员在编写代码的时候,没有对用户输入数据的合法性进行判断,注入者可以在表单中输入一段数据库查询代码并提交,程序将提交的信息拼凑生成一个完整s ...

  10. node.js开发hello world

    在你的 D 盘下面创建一个 server.js,写入以下内容 ---------------------------------------------------- var http = requi ...