博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Polynomial Division 数学题
阅读量:4317 次
发布时间:2019-06-06

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

询问一个多项式能否整除一个一次函数。a * x + b

注意到如果能整除,就比如是x^2 + 2 * x + 1能整除2 * x + 2

那么它必定能整除2 * x + 2的根,也就是和根肯定有交点。

因为你能整除,也就是(x^2 + 2 * x + 1) = k * (2 * x + 2)

那么k * (2 * x + 2)还是条直线。唯独使得2 * x + 2 = 0那个点是不会变的。

然后就是bit维护了。相当于询问[L, R]中,这一段的和,

注意特判一下b = 0,有点不同。

 

#include 
#include
#include
#include
#include
#include
#define IOS ios::sync_with_stdio(false)using namespace std;#define inf (0x3f3f3f3f)typedef long long int LL;#include
#include
#include
#include
#include
#include
#include
#include
const int MOD = 1e9 + 7;const int maxn = 1e5 + 20;LL powx[maxn];LL quick_pow(LL a, LL b, int MOD) { LL ans = 1; LL base = a; while (b > 0) { if (b & 1) { ans *= base; if (ans >= MOD) ans %= MOD; } b >>= 1; base *= base; if (base >= MOD) base %= MOD; } return ans;}LL c[maxn];int n, a, b, q;int lowbit(int x) { return x & (-x);}void upDate(int pos, LL val) { while (pos <= n) { c[pos] += val; pos += lowbit(pos); if (c[pos] >= MOD) c[pos] %= MOD; }}LL get_sum(int pos) { LL ans = 0; while (pos) { ans += c[pos]; pos -= lowbit(pos); if (ans >= MOD) ans %= MOD; } return ans;}LL arr[maxn];void work() {// cout << quick_pow(2, 4, MOD) << endl; scanf("%d%d%d%d", &n, &a, &b, &q); powx[0] = 1; powx[1] = -b * quick_pow(a, MOD - 2, MOD) % MOD; for (int i = 2; i <= n; ++i) { powx[i] = powx[i - 1] * powx[1] % MOD; } for (int i = 1; i <= n; ++i) { LL x; scanf("%lld", &x); arr[i] = x; upDate(i, x * powx[i - 1] % MOD); } if (b == 0) { while (q--) { int flag; scanf("%d", &flag); if (flag == 1) { int pos, val; scanf("%d%d", &pos, &val); ++pos; arr[pos] = val; } else { int L, R; scanf("%d%d", &L, &R); L++; R++; if (arr[L] == 0) { printf("Yes\n"); } else printf("No\n"); } } return; } while (q--) { int flag; scanf("%d", &flag); if (flag == 1) { int pos; LL val; scanf("%d%lld", &pos, &val); pos++; LL now = (get_sum(pos) + MOD - get_sum(pos - 1)) % MOD; upDate(pos, -now); upDate(pos, val * powx[pos - 1] % MOD); } else { int L, R; scanf("%d%d", &L, &R); L++; R++; LL now = (get_sum(R) - get_sum(L - 1) + MOD) % MOD; if (now == 0) { printf("Yes\n"); } else printf("No\n"); } }}int main() {#ifdef local freopen("data.txt", "r", stdin);// freopen("data.txt", "w", stdout);#endif work(); return 0;}
View Code

 

转载于:https://www.cnblogs.com/liuweimingcprogram/p/6348987.html

你可能感兴趣的文章
springMVC中一个class中的多个方法
查看>>
Linux系统安装出错后出现grub rescue的修复方法
查看>>
线段树模板整理
查看>>
[教程][6月4日更新]VMware 8.02虚拟机安装MAC lion 10.7.3教程 附送原版提取镜像InstallESD.iso!...
查看>>
[iOS问题归总]iPhone上传项目遇到的问题
查看>>
Python天天美味(总) --转
查看>>
Spring Framework tutorial
查看>>
【VS开发】win7下让程序默认以管理员身份运行
查看>>
【机器学习】Learning to Rank 简介
查看>>
Unity 使用实体类
查看>>
【转】通过文件锁实现,程序开始运行时,先判断文件是否存在,若存在则表明该程序已经在运行了,如果不存在就用open函数创建该文件,程序退出时关闭文件并删除文件...
查看>>
MySQL常见注意事项及优化
查看>>
流畅的Python (Fluent Python) —— 前言
查看>>
Jquery-menu-aim流畅的菜单滑动体验
查看>>
Jquery EasyUI修改行背景的两种方式
查看>>
生成器模式(Builder)C++实现
查看>>
Centos 7.5安装 Redis 5.0.0
查看>>
嵌入式Linux学习笔记(0)基础命令。——Arvin
查看>>
二分图匹配
查看>>
c++ 模板template
查看>>