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. 安装完最小化 RHEL/CentOS 7 后需要做的 30 件事情(二)

    本文导航 -7. 安装 PHP0 -8. 安装 MariaDB 数据库 -9. 安装和配置 SSH 服务器 -10. 安装 GCC (GNU 编译器集) -11. 安装 Java 7. 安装 PHP ...

  2. Kinect关于PlayerIndex和SkeletonId之间的关系。

    项目中要锁定玩家骨骼后抠图, 一时没有灵感.google 关键词: the ralationship about skeletonid and playerindex. 结论: Player Segm ...

  3. CSS系列(6) CSS通配符详解

    通配符使用星号*表示,意思是“所有的”. 平时使用电脑,比如要搜索C盘里所有的网页,可以使用 *.html来搜索,.html是网页的后缀名,*代表了所有网页的名称: 也就是使用 * 加后缀名,就可以在 ...

  4. windows 10的资源管理器不显示映射的网络驱动器怎么办?

    最近在使用映射网络驱动器的时候出现一个奇怪的现象.事情源于我在资源管理器里面映射了来自多个不同账号的网络驱动器.使用的是win10系统.映射不同账号的网络驱动器是不允许的.于是只能删掉其他账号和凭证重 ...

  5. jmeter学习(二),如何安装jmeter?

    官网地址:http://jmeter.apache.org/download_jmeter.cgi 如下图数字3.2表示的是版本号,jmeter是基于java的压力测试工具.所以运行环境一定要满足最低 ...

  6. Kotlin将Realm提升到更高层次

    作者:Víctor Manuel Pineda 时间:Feb 14, 2017 原文链接:https://antonioleiva.com/kotlin-realm-extensions/ 当有人问我 ...

  7. spring boot打war包启动Tomcat失败

    Tomcat启动失败:最后一个causy by :java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getMa ...

  8. [18/12/3]蓝桥杯 练习系统 入门级别 Fibonacci数列求模问题 题解思路

    前言略. 看到这个题目本来应该很高兴的,因为什么,因为太TM的基础了啊! 可是当你用常规方法尝试提交OJ时你会发现..hhh...运行超时..(开心地摇起了呆毛 //Fibonacci数列递归一般问题 ...

  9. PHP异常处理类(文件上传提示)

    知识点: 大部分时候我们的代码总有各种各样的bug,新手程序员(比如我)最经常的工作就是不停的报错和echo变量,一个好的异常处理类可以帮我们更快+更容易理解报错代码的问题,同时,异常处理还可以避免一 ...

  10. nodejs & docker

    nodejs & docker https://github.com/xgqfrms-GitHub/Node.js/blob/master/Docker-Nodejs/translation. ...