Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h> //эм оккк
- #define FASTER() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
- #define ff first
- #define ss second
- #define pb push_back
- #define all(a) a.begin(), a.end()
- #define int ll
- typedef long long ll;
- using namespace std;
- const int mod1 = 12345, mod2 = 23456;
- const ll inf = LLONG_MAX - 1000;
- struct segTree {
- vector <ll> mins, maxes;
- int sz = 1;
- segTree(vector <ll> &v) {
- int n = v.size();
- while(sz < n) {
- sz <<= 1;
- }
- mins = vector <ll> (2 * sz - 1, inf);
- maxes = vector <ll> (2 * sz - 1, -inf);
- build(0, 0, sz, v);
- }
- void build(int x, int lx, int rx, vector <ll> &v) {
- if(rx - lx == 1) {
- if(lx < (int)v.size()) {
- mins[x] = v[lx];
- maxes[x] = v[lx];
- }
- } else {
- int m = (lx + rx) >> 1;
- build(2 * x + 1, lx, m, v);
- build(2 * x + 2, m, rx, v);
- mins[x] = min(mins[2 * x + 1], mins[2 * x + 2]);
- maxes[x] = max(maxes[2 * x + 1], maxes[2 * x + 2]);
- }
- }
- void upd(int x, int lx, int rx, int idx, int val) {
- if(rx - lx == 1) {
- mins[x] = val;
- maxes[x] = val;
- return;
- }
- int m = (lx + rx) >> 1;
- if(idx < m) {
- upd(2 * x + 1, lx, m, idx, val);
- } else {
- upd(2 * x + 2, m, rx, idx, val);
- }
- mins[x] = min(mins[2 * x + 1], mins[2 * x + 2]);
- maxes[x] = max(maxes[2 * x + 1], maxes[2 * x + 2]);
- }
- void upd(int idx, int val) {
- upd(0, 0, sz, idx, val);
- }
- pair <ll, ll> get(int x, int lx, int rx, int l, int r) { //1-st is min. 2nd - max
- if(lx >= r || rx <= l) {
- return {inf, -inf};
- }
- if(lx >= l && rx <= r) {
- return {mins[x], maxes[x]};
- }
- int m = (lx + rx) >> 1;
- auto ans1 = get(2 * x + 1, lx, m, l, r),
- ans2 = get(2 * x + 2, m, rx, l, r);
- ll mn = min(ans1.ff, ans2.ff);
- ll mx = max(ans1.ss, ans2.ss);
- return {mn, mx};
- }
- ll get(int l, int r) {
- auto ans = get(0, 0, sz, l, r);
- return ans.ss - ans.ff;
- }
- };
- signed main() {
- FASTER();
- int k;
- cin >> k;
- vector <pair <int, int>> q(k);
- int n = 1e5 + 20;
- vector <ll> v(n);
- for(int i = 1; i <= n; i++) {
- v[i - 1] = i * i % mod1 + i * i * i % mod2;
- }
- segTree st(v);
- for(int i = 0; i < k; i++) {
- int x, y;
- cin >> x >> y;
- if(x < 0) {
- st.upd (-x - 1, y);
- } else {
- cout << st.get (x - 1, y) << '\n';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement