https://www.hackerrank.com/contests/101hack45/challenges/polynomial-division

询问一个多项式能否整除一个一次函数。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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int MOD = 1e9 + ;
const int maxn = 1e5 + ;
LL powx[maxn];
LL quick_pow(LL a, LL b, int MOD) {
LL ans = ;
LL base = a;
while (b > ) {
if (b & ) {
ans *= base;
if (ans >= MOD) ans %= MOD;
}
b >>= ;
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 = ;
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[] = ;
powx[] = -b * quick_pow(a, MOD - , MOD) % MOD;
for (int i = ; i <= n; ++i) {
powx[i] = powx[i - ] * powx[] % MOD;
}
for (int i = ; i <= n; ++i) {
LL x;
scanf("%lld", &x);
arr[i] = x;
upDate(i, x * powx[i - ] % MOD);
}
if (b == ) {
while (q--) {
int flag;
scanf("%d", &flag);
if (flag == ) {
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] == ) {
printf("Yes\n");
} else printf("No\n");
}
}
return;
}
while (q--) {
int flag;
scanf("%d", &flag);
if (flag == ) {
int pos;
LL val;
scanf("%d%lld", &pos, &val);
pos++;
LL now = (get_sum(pos) + MOD - get_sum(pos - )) % MOD;
upDate(pos, -now);
upDate(pos, val * powx[pos - ] % MOD);
} else {
int L, R;
scanf("%d%d", &L, &R);
L++;
R++;
LL now = (get_sum(R) - get_sum(L - ) + MOD) % MOD;
if (now == ) {
printf("Yes\n");
} else printf("No\n");
}
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

Polynomial Division 数学题的更多相关文章

  1. FOJ 1607 Greedy division 数学题

    题目地址: http://acm.fzu.edu.cn/problem.php?pid=1607 给定一个n,将n平均分成m份,问有几种方法,每种方法中找出最大的数.思路:就是求n的因子数.先将每个数 ...

  2. 二维码详解(QR Code)

    作者:王子旭链接:https://zhuanlan.zhihu.com/p/21463650来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 2016.7.5 更新:长文 ...

  3. CRC 概述

    Acquired from: ftp.adelaide.edu.au:/pub/rocksoft/crc_v3.txt or ftp://ftp.rocksoft.com/papers/crc_v3. ...

  4. [Matlab] Galois Field arrays

    Operations supported for Galois Field arrays: + - - Addition and subtraction of Galois arrays. * / \ ...

  5. Polynomial ( Arithmetic and Algebra) CGAL 4.13 -User Manual

    1 Fundamentals A polynomial is either zero, or can be written as the sum of one or more non-zero ter ...

  6. polynomial time

    https://en.wikipedia.org/wiki/Time_complexity#Polynomial_time An algorithm is said to be of polynomi ...

  7. (多项式)因式分解定理(Factor theorem)与多项式剩余定理(Polynomial remainder theorem)(多项式长除法)

    (多项式的)因式分解定理(factor theorem)是多项式剩余定理的特殊情况,也就是余项为 0 的情形. 0. 多项式长除法(Polynomial long division) Polynomi ...

  8. 水题挑战6: CF1444A DIvision

    A. Division time limit per test1 second memory limit per test512 megabytes inputstandard input outpu ...

  9. python from __future__ import division

    1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...

随机推荐

  1. [Hibernate Search] (3) 基础查询

    基础查询 眼下我们仅仅用到了基于keyword的查询,实际上Hibenrate Search DSL还提供了其他的查询方式,以下我们就来一探到底. 映射API和查询API 对于映射API.我们能够通过 ...

  2. 【Mongodb教程 第九课 】MongoDB 删除文档

    remove() 方法 MongoDB的 remove() 方法用于从集合中删除文档.remove() 方法接受两个参数.第一个是删除criteria ,第二是justOne标志: deletion ...

  3. 海思HI3516A开发板顺利上线

    有图有真相.

  4. css3最新版中文参考手册在线浏览

    对于CSS 3.0,它对于我们Web设计人员来说不只是新奇的技术,更重要的是这些全新概念的Web应用给我们的设计开发提高了效率以及更多的无限可能性,我们将不必再依赖图片或者 Javascript 去完 ...

  5. aix用户登录次数受限问题(3004-300 输入了无效的登录名或password)

    当登录AIX系统.username或password不对以至于多次登录,超过系统设定的次数,怎样解锁: 1.用root用户登录系统 2.chuser unsuccessful_login_count= ...

  6. Interpret bytes as packed binary data

    7.1. struct — Interpret bytes as packed binary data — Python 3.6.5 documentation https://docs.python ...

  7. apache配置访问限制

    1.禁止访问某些文件/目录 增加Files选项来控制,比如要不允许访问 .txt扩展名的文件,保护php类库: <Files ~ "\.txt$"> Order all ...

  8. Genymotion设置网络桥接

    1,打开Genymotion,找到对应的模拟器,点击“设置”按钮 2,在网络选项中选择桥接 Bridge

  9. 注册中心Eureka页面添加用户认证

    我们需要登录即可访问到Eureka服务,这样其实是不安全的 为Eureka添加用户认证. 第一步,为itcast-microservice-eureka添加安全认证依赖: 第二步,增加applicat ...

  10. I.MX6 AW-NB177NF wifi HAL 调试修改

    /************************************************************************* * I.MX6 AW-NB177NF wifi H ...