AcWing 1622. 奇妙序列
原题链接
简单
作者:
Lemmon_kk
,
2021-04-19 15:23:24
,
所有人可见
,
阅读 376
上来一看就是维护一个代数结构
以为要来个线段树 瞬间不想写了
结果发现每次都是整个区间操作 即只对线段树根节点操作
想存double水一下结果数据有点强 水不过去
所以就写个逆元就好啦
感觉这个还没上个难
typedef long long LL;
const LL mod = 1e9 + 7;
class Fancy {
public:
LL mul = 1, add = 0;
vector<LL> nums;
Fancy() {
mul = 1, add = 0;
nums.clear();
}
LL qmi(LL a, LL b){
LL res = 1;
a %= mod;
while(b){
if(b & 1) (res *= a) %= mod;
a = a % mod * a % mod;
b >>= 1;
}
return res;
}
void append(int val) {
nums.push_back((val - add) % mod * qmi(mul, mod - 2) % mod);
}
void addAll(int inc) {
(add += inc) %= mod;
}
void multAll(int m) {
(mul *= m) %= mod;
(add *= m) %= mod;
}
int getIndex(int idx) {
if(idx >= nums.size()) return -1;
return (nums[idx] % mod * mul % mod + add + mod) % mod;
}
};
/**
* Your Fancy object will be instantiated and called as such:
* Fancy* obj = new Fancy();
* obj->append(val);
* obj->addAll(inc);
* obj->multAll(m);
* int param_4 = obj->getIndex(idx);
*/