博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AC日记——算术天才⑨与等差数列 bzoj 4373
阅读量:6836 次
发布时间:2019-06-26

本文共 3198 字,大约阅读时间需要 10 分钟。

 

思路:

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

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

    2,gcd==k;

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

 

来,上代码:

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

 

转载于:https://www.cnblogs.com/IUUUUUUUskyyy/p/6815644.html

你可能感兴趣的文章
debian8修改kde桌面语言
查看>>
PHP对于数据库的基本操作——更新数据
查看>>
How HashMap works in Java
查看>>
洛谷P2057 善意的投票
查看>>
UVa11401 Triangle Counting
查看>>
MongoDB
查看>>
深入Android 【三】 —— 组件入门
查看>>
Matlab DIP(瓦)ch11表示与描述练习
查看>>
【Echo】实验 -- 实现 C/C++下TCP, 服务器/客户端 通讯
查看>>
16、SpringBoot-CRUD错误处理机制(3)
查看>>
7、NIO--字符集Charset
查看>>
2-JSF html标签
查看>>
队列queue 代码
查看>>
Python-mysql 权限 pymysql 注入共计
查看>>
HashSet、LinkedHashSet、TreeSet
查看>>
ios 远程推送
查看>>
halcon算子翻译——compose5
查看>>
安装office2010提示要安装MSXML6.10.1129.0解决方法
查看>>
作业6随笔
查看>>
Github提交本地代码
查看>>