Polynomial Division 数学题
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 数学题的更多相关文章
- FOJ 1607 Greedy division 数学题
题目地址: http://acm.fzu.edu.cn/problem.php?pid=1607 给定一个n,将n平均分成m份,问有几种方法,每种方法中找出最大的数.思路:就是求n的因子数.先将每个数 ...
- 二维码详解(QR Code)
作者:王子旭链接:https://zhuanlan.zhihu.com/p/21463650来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 2016.7.5 更新:长文 ...
- CRC 概述
Acquired from: ftp.adelaide.edu.au:/pub/rocksoft/crc_v3.txt or ftp://ftp.rocksoft.com/papers/crc_v3. ...
- [Matlab] Galois Field arrays
Operations supported for Galois Field arrays: + - - Addition and subtraction of Galois arrays. * / \ ...
- 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 ...
- polynomial time
https://en.wikipedia.org/wiki/Time_complexity#Polynomial_time An algorithm is said to be of polynomi ...
- (多项式)因式分解定理(Factor theorem)与多项式剩余定理(Polynomial remainder theorem)(多项式长除法)
(多项式的)因式分解定理(factor theorem)是多项式剩余定理的特殊情况,也就是余项为 0 的情形. 0. 多项式长除法(Polynomial long division) Polynomi ...
- 水题挑战6: CF1444A DIvision
A. Division time limit per test1 second memory limit per test512 megabytes inputstandard input outpu ...
- python from __future__ import division
1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...
随机推荐
- jquery验证后ajax提交,返回消息怎样统一显示的问题
/* jquery验证后ajax提交.返回消息怎样跟jquery验证体系统一显示的问题,网上查了非常多资料.都没有找到明白的答案,通过数小时的尝试,最终攻克了,现举一个简单的样例,给须要的人參考參考吧 ...
- 深度学习笔记之CNN(卷积神经网络)基础
不多说,直接上干货! 卷积神经网络(ConvolutionalNeural Networks,简称CNN)提出于20世纪60年代,由Hubel和Wiesel在研究猫脑皮层中用于局部敏感和方向选择的神经 ...
- 使用css属性line-height实现文字垂直居中的问题
使用css属性line-height实现文字垂直居中的问题 1.使用css属性line-height实现文字垂直居中 方法比较简单,但是只能实现单行文字的垂直居中. 单行垂直居中效果如下: 要是p ...
- 一场由过滤器Filter引发的血案
一场由过滤器Filter引发的血案 事件起因 本来应该是下图的登录界面 变成了这样 What's the fuck????? 抓狂 原因 解决方法: 在过滤器中给资源文件开个绿色通道
- Java 基本类型和对象类型的区别
Java 基本类型和对象类型的区别 基本类型: int long byte float double char boolean short 对象类型: Integer Long Byte Float ...
- 实现的是Linux和Windows之间的一种共享--samba
samba 基本配置及自定义控制 https://www.cnblogs.com/l-hh/p/9473937.html Samba简介: Samba实现的是Linux和Windows之间的一种共享, ...
- hdu 2829(四边形优化 && 枚举最后一个放炸弹的地方)
Lawrence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- dropZone 回显图片
初始化dropzone的图片信息 var dropVar = this; var mockFile = { name: "myiamge.jpg", //需要显示给用户的图片名 s ...
- ACGAN 论文笔记
<Conditional Image Synthesis With Auxiliary Classifier GANs> Odena A, Olah C, Shlens J. Condit ...
- Entity Framework Code First 迁移
Entity Framework CodeFirst数据迁移 http://www.cnblogs.com/aehyok/p/3325459.html Entity Framework Code Fi ...