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 ;
}

最新文章

  1. 敏捷组织中PMO应遵循的准则
  2. IDEA 新建文件默认加入CVS
  3. VMware ESXI磁盘下载虚拟机迁移到另一台VMware ESXI
  4. does not support ASP.NET compatibility 错误
  5. Android第三方授权(新浪微博篇)
  6. Android 透明Button
  7. 【锋利的Jquery】读书笔记十一
  8. java 分解质因数
  9. 科普:String hashCode 方法为什么选择数字31作为乘子
  10. 关于 Microsoft Dynamics CRM has encountered an error 弹窗的问题
  11. 给定两个字符串 s 和 t,它们只包含小写字母。 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。 请找出在 t 中被添加的字母。
  12. FasterRCNN代码解读
  13. 3ds max学习笔记(十四)-- (FFD自由变形)
  14. mongodb系列~mongodb慢语句(2)
  15. 初识vuejs
  16. C# 校验给定的ip地址是否合法
  17. BeautifulSoup与Xpath解析库总结
  18. docker桥接
  19. centos安装后,连接不上网络,yum命令执行can not find a valid baseurl for repo: base/7/x86-64
  20. PHP第三方登录

热门文章

  1. 在XX公司工作第二天,维护已有代码
  2. Mongodb for PHP教程之入门安装
  3. Atitit. 软件GUIbutton与仪表盘--webserver区--获取apache配置文件路径 linux and apache的启动、停止、重新启动
  4. ImageLoader实现图片异步载入
  5. 【iOS系列】- UITableView的使用技巧
  6. 2016/05/25 get和post的区别
  7. XML中的CDATA是什么?PCDATA是什么?
  8. HDU3001 Travelling —— 状压DP(三进制)
  9. action 与 action 之间的跳转
  10. BZOJ_3998_[TJOI2015]弦论_后缀自动机