Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define INF 1e9
- const int N=100000;
- int t1[4*N], t2[4*N];
- void build(int v, int l, int r) {
- if (l == r) {
- t1[v] = (long long)(l*l)%12345 + (long long)(l*l*l)%23456;
- t2[v] = t1[v];
- } else {
- int m=(l+r)/2;
- build(2*v, l, m);
- build(2*v+1, m+1, r);
- t1[v] = min(t1[2*v], t1[2*v+1]);
- t2[v] = max(t2[2*v], t2[2*v+1]);
- }
- }
- int get_min(int v, int l, int r, int lt, int rt) {
- if (l > r)
- return INF;
- if (l==lt && r==rt)
- return t1[v];
- int m=(l+r)/2;
- get_min(2*v, l, m, lt, rt);
- get_min(2*v+1, m+1, r, lt, rt);
- }
- int get_max(int v, int l, int r, int lt, int rt) {
- if (l > r)
- return -INF;
- if (l==lt && r==rt)
- return t2[v];
- int m=(l+r)/2;
- get_max(2*v, l, m, lt, rt);
- get_max(2*v+1, m+1, r, lt, rt);
- }
- void update(int v, int l, int r, int pos, int x) {
- if (l == r) {
- t1[v] = x;
- t2[v] = x;
- } else {
- int m=(l+r)/2;
- if (pos <= m)
- update(2*v, l, m, pos, x);
- else
- update(2*v+1, m+1, r, pos, x);
- t1[v] = min(t1[2*v], t1[2*v+1]);
- t2[v] = max(t2[2*v], t2[2*v+1]);
- }
- }
- int main() {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- build(1, 1, N);
- int K=0; cin >> K;
- for (int i=0; i<K; i++) {
- int x=0, y=0; cin >> x >> y;
- if (x > 0) {
- cout << get_max(1, 1, N, x, y) - get_min(1, 1, N, x, y ) << '\n';
- } else {
- update(1, 1, N, -x, y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement