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. Android +NDK+eclipse+opengl ES2.0 开启深度測试

    參考:https://www.opengl.org/discussion_boards/showthread.php/172736-OpenGL-ES-Depth-Buffer-Problem 环境: ...

  2. kill mediaserver脚本

    #!/bin/bash adb shell kill $(adb shell ps | grep mediaserver | awk '{print $2}') adb shell pm clear ...

  3. Android开发之自己定义Spinner样式的效果实现(源码实现)

    android系统自带的Spinner样式是远远满足不了我们实际开发过程中对Spinner UI风格的要求,因此我们肯定须要为了切合整个应用的风格,改动我们的Spinner样式.系统给我们提供了两种常 ...

  4. codeforces 394E Lightbulb for Minister 简单几何

    题目链接:点我点我 题意:给定n个点. 以下n行给出这n个点坐标. 给定m个点,以下m行给出这m个点坐标. 这m个点是一个凸包,顺时针给出的. 问:在凸包上随意找一个点(x, y) 使得这个点距离n个 ...

  5. 找不到方法 Void Newtonsoft.Json.JsonConvert.set_DefaultSettings

    找不到方法 Void Newtonsoft.Json.JsonConvert.set_DefaultSettings 因为 Newtonsoft.Json.dll 的版本号问题: C:\Program ...

  6. 什么是 XML Schema?

    XML Schema 的作用是定义 XML 文档的合法构建模块,类似 DTD. XML Schema: 定义可出现在文档中的元素 定义可出现在文档中的属性 定义哪个元素是子元素 定义子元素的次序 定义 ...

  7. Codeforces Round #261 (Div. 2)——Pashmak and Graph

    题目链接 题意: n个点.m个边的有向图.每条边有一个权值,求一条最长的路径,使得路径上边值严格递增.输出路径长度 )) 分析: 由于路径上会有反复点,而边不会反复.所以最開始想的是以边为状态进行DP ...

  8. ELF和a.out文件格式的比较

    本文讨论了 UNIX/LINUX 平台下三种主要的可执行文件格式:a.out(assembler and link editor output 汇编器和链接编辑器的输出).COFF(Common Ob ...

  9. 【Codeforces 915E】 Physical Education Lessons

    [题目链接] 点击打开链接 [算法] 线段树,注意数据量大,要动态开点 [代码] #include<bits/stdc++.h> using namespace std; ; ,root ...

  10. c#截屏功能的实现

    using System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.Ru ...