题目链接
分类:
dp
number theory
data structures
1 x y
查询从城市x到城市y所需要耗费的时间;2 x y
修改第x个城市的拥堵值 ax 为 y 。Memory Limited Ecxeed
!class SegmentTree {
public:
#define lson (root << 1)
#define rson (root << 1 | 1)
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
int t[maxn << 2][N];
void pushup(int root) {
rep(i, 0, N) {
int x = (i + t[lson][i]) % N;
t[root][i] = t[lson][i] + t[rson][x];
}
}
void build(int l, int r, int root) {
if (l == r) {
int x;
scanf("%d", &x);
rep(i, 0, N) t[root][i] = (i % x) ? 1 : 2;
return;
}
int mid = l + r >> 1;
build(l, mid, lson);
build(mid + 1, r, rson);
pushup(root);
}
void update(int a, int b, int l, int r, int val, int root) {
if (l <= a && b <= r) {
rep(i, 0, N) t[root][i] = (i % val) ? 1 : 2;
return;
}
int mid = a + b >> 1;
if (l <= mid) update(a, mid, l, r, val, lson);
if (r > mid) update(mid + 1, b, l, r, val, rson);
pushup(root);
}
int query(int a, int b, int l, int r, int x, int root) {
if (l <= a && b <= r)
return x + t[root][x % N];
int mid = a + b >> 1;
if (l <= mid) x = query(a, mid, l, r, x, lson);
if (r > mid) x = query(mid + 1, b, l, r, x, rson);
return x;
}
#undef lenr
#undef lenl
#undef lent
#undef rson
#undef lson
} T;
inline void solve() {
int n, q;
scanf("%d", &n);
T.build(1, n, 1);
scanf("%d", &q);
while (q--) {
char op[2];
int x, y;
scanf("%s%d%d", op, &x, &y);
if (op[0] == 'C') T.update(1, n, x, x, y, 1);
else printf("%d\n", T.query(1, n, x, y - 1, 0, 1));
}
}