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,有点不同。

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <assert.h>
  7. #define IOS ios::sync_with_stdio(false)
  8. using namespace std;
  9. #define inf (0x3f3f3f3f)
  10. typedef long long int LL;
  11.  
  12. #include <iostream>
  13. #include <sstream>
  14. #include <vector>
  15. #include <set>
  16. #include <map>
  17. #include <queue>
  18. #include <string>
  19. #include <bitset>
  20. const int MOD = 1e9 + ;
  21. const int maxn = 1e5 + ;
  22. LL powx[maxn];
  23. LL quick_pow(LL a, LL b, int MOD) {
  24. LL ans = ;
  25. LL base = a;
  26. while (b > ) {
  27. if (b & ) {
  28. ans *= base;
  29. if (ans >= MOD) ans %= MOD;
  30. }
  31. b >>= ;
  32. base *= base;
  33. if (base >= MOD) base %= MOD;
  34. }
  35. return ans;
  36. }
  37. LL c[maxn];
  38. int n, a, b, q;
  39. int lowbit(int x) {
  40. return x & (-x);
  41. }
  42. void upDate(int pos, LL val) {
  43. while (pos <= n) {
  44. c[pos] += val;
  45. pos += lowbit(pos);
  46. if (c[pos] >= MOD) c[pos] %= MOD;
  47. }
  48. }
  49. LL get_sum(int pos) {
  50. LL ans = ;
  51. while (pos) {
  52. ans += c[pos];
  53. pos -= lowbit(pos);
  54. if (ans >= MOD) ans %= MOD;
  55. }
  56. return ans;
  57. }
  58. LL arr[maxn];
  59. void work() {
  60. // cout << quick_pow(2, 4, MOD) << endl;
  61. scanf("%d%d%d%d", &n, &a, &b, &q);
  62. powx[] = ;
  63. powx[] = -b * quick_pow(a, MOD - , MOD) % MOD;
  64. for (int i = ; i <= n; ++i) {
  65. powx[i] = powx[i - ] * powx[] % MOD;
  66. }
  67. for (int i = ; i <= n; ++i) {
  68. LL x;
  69. scanf("%lld", &x);
  70. arr[i] = x;
  71. upDate(i, x * powx[i - ] % MOD);
  72. }
  73. if (b == ) {
  74. while (q--) {
  75. int flag;
  76. scanf("%d", &flag);
  77. if (flag == ) {
  78. int pos, val;
  79. scanf("%d%d", &pos, &val);
  80. ++pos;
  81. arr[pos] = val;
  82. } else {
  83. int L, R;
  84. scanf("%d%d", &L, &R);
  85. L++;
  86. R++;
  87. if (arr[L] == ) {
  88. printf("Yes\n");
  89. } else printf("No\n");
  90. }
  91. }
  92. return;
  93. }
  94. while (q--) {
  95. int flag;
  96. scanf("%d", &flag);
  97. if (flag == ) {
  98. int pos;
  99. LL val;
  100. scanf("%d%lld", &pos, &val);
  101. pos++;
  102. LL now = (get_sum(pos) + MOD - get_sum(pos - )) % MOD;
  103. upDate(pos, -now);
  104. upDate(pos, val * powx[pos - ] % MOD);
  105. } else {
  106. int L, R;
  107. scanf("%d%d", &L, &R);
  108. L++;
  109. R++;
  110. LL now = (get_sum(R) - get_sum(L - ) + MOD) % MOD;
  111. if (now == ) {
  112. printf("Yes\n");
  113. } else printf("No\n");
  114. }
  115. }
  116. }
  117.  
  118. int main() {
  119. #ifdef local
  120. freopen("data.txt", "r", stdin);
  121. // freopen("data.txt", "w", stdout);
  122. #endif
  123. work();
  124. return ;
  125. }

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. Win7 本地打印后台处理程序服务没有运 怎么办

    找到名为Print Spooler的服务,启动类型改为自动,服务状态改为启动即可.

  2. 【Mongodb教程 第一课补加课2 】MongoDB下,启动服务时,出现“服务没有响应控制功能”解决方法

    如图,如果通过下列代码,添加服务后,使用net start命令出现这样的问题时,可以参考下我的解决方法. D:\MongoDB>mongod --dbpath D:\MongoDB\Data - ...

  3. 【bzoj2462】[BeiJing2011]矩阵模板

    #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> # ...

  4. scikit-learn(1) 第一个例子说明

    第一个 scikit-learn例子 ................................................................................. ...

  5. Linux 下的静态(函数)库、动态(函数)库

    0. 基本 在命名上,静态库的名字一般是 libxxx.a,动态库的名字一般是 libxxx.so,有时 libxxx.so.major.minor,xxx 是该 lib 的名字,major 是主版本 ...

  6. AppiumLibrary用户关键字

    *** Settings *** Library AppiumLibrary Library AutoItLibrary Library os *** Keywords *** xpath应该匹配次数 ...

  7. bzoj3769

    树形dp %%%popoqqq 设dp[i][j]表示当前i个节点的树,深度小于等于j的树的个数 那么dp[i][j] = sigma(dp[k][j-1]*dp[n-k-1][j-1]) 比较好理解 ...

  8. 【415】C语言文件读写

    A program can open and close, and read from, and write to, a file that is defined by the user This i ...

  9. 13_传智播客iOS视频教程_OC程序的编译链接

    C程序的编译.链接.执行怎么来的?在.C文件里面写上符合C语言部分的源代码.OC也是一样的.记住:OC程序的后缀名是.m. 为什么要链接?第一个.o的目标文件里面它启动不了.因为它没有启动代码我们要加 ...

  10. linux中的C里面使用pthread_mutex_t锁(转载)

    转自:http://blog.csdn.net/w397090770/article/details/7264315 linux下为了多线程同步,通常用到锁的概念. posix下抽象了一个锁类型的结构 ...