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 ...
随机推荐
- Win7 本地打印后台处理程序服务没有运 怎么办
找到名为Print Spooler的服务,启动类型改为自动,服务状态改为启动即可.
- 【Mongodb教程 第一课补加课2 】MongoDB下,启动服务时,出现“服务没有响应控制功能”解决方法
如图,如果通过下列代码,添加服务后,使用net start命令出现这样的问题时,可以参考下我的解决方法. D:\MongoDB>mongod --dbpath D:\MongoDB\Data - ...
- 【bzoj2462】[BeiJing2011]矩阵模板
#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> # ...
- scikit-learn(1) 第一个例子说明
第一个 scikit-learn例子 ................................................................................. ...
- Linux 下的静态(函数)库、动态(函数)库
0. 基本 在命名上,静态库的名字一般是 libxxx.a,动态库的名字一般是 libxxx.so,有时 libxxx.so.major.minor,xxx 是该 lib 的名字,major 是主版本 ...
- AppiumLibrary用户关键字
*** Settings *** Library AppiumLibrary Library AutoItLibrary Library os *** Keywords *** xpath应该匹配次数 ...
- bzoj3769
树形dp %%%popoqqq 设dp[i][j]表示当前i个节点的树,深度小于等于j的树的个数 那么dp[i][j] = sigma(dp[k][j-1]*dp[n-k-1][j-1]) 比较好理解 ...
- 【415】C语言文件读写
A program can open and close, and read from, and write to, a file that is defined by the user This i ...
- 13_传智播客iOS视频教程_OC程序的编译链接
C程序的编译.链接.执行怎么来的?在.C文件里面写上符合C语言部分的源代码.OC也是一样的.记住:OC程序的后缀名是.m. 为什么要链接?第一个.o的目标文件里面它启动不了.因为它没有启动代码我们要加 ...
- linux中的C里面使用pthread_mutex_t锁(转载)
转自:http://blog.csdn.net/w397090770/article/details/7264315 linux下为了多线程同步,通常用到锁的概念. posix下抽象了一个锁类型的结构 ...