题目:
CodeForces - 438D:The Child and Sequence
题意:
给定一个序列,有三种操作:(1)区间求和(2)区间对一个数取模(3)单点修改
分析:
这个题的难点在于区间取模,并没有什么好的方法能快速维护区间和,考虑暴力取模:
首先,只有 A[x] >= mod,取模操作才有意义,那么就可以维护区间最大值,去找到需要取模的数;这样暴力的复杂度如何呢?当 mod <= A[x]/2,那么有:A[x]%mod <= A[x]/2;当 mod > A[x]/2 时,又有 mod <= A[x],同样有:A[x]%mod <= A[x]/2;所以每取一次模,值最差都要减小一半,那么每个数最多操作 log 次;所以复杂度为O(MlogAlogA)
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5+15;
int n,m,op,x,l,r,k,a[maxn];
LL tr[maxn<<