Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
- // #pragma comment(linker, "/stack:200000000"]
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <unordered_set>
- #include <unordered_map>
- #include <set>
- #include <map>
- #include <queue>
- #include <deque>
- #include <bitset>
- #include <stack>
- #include <random>
- #include <fstream>
- #include <sstream>
- #include <chrono>
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define ld long double
- #define hm unordered_map
- #define pii pair<int, int>
- #define sz(a) (int)a.size()
- #define all(a) a.begin(), a.end()
- #define cinv(v) for (auto& x: v) cin >> x
- #define fr(i, n) for (int i = 0; i < n; ++i)
- #define fl(i, l, n) for (int i = l; i < n; ++i)
- #define int ll
- template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
- template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
- using namespace std;
- #ifdef LOCAL
- #define dbg(x) cerr << #x << " : " << x << '\n'
- const int maxn = 20;
- #else
- #define dbg(x)
- const int maxn = 2e5 + 20;
- #endif
- //tg: @galebickosikasa
- ostream& operator << (ostream& out, const pii& v) {
- out << v.fi << ", " << v.se;
- return out;
- }
- template<typename T> ostream& operator << (ostream& out, const vector<T>& v) {
- for (auto& x: v) out << x << " ";
- return out;
- }
- istream& operator >> (istream& in, pii& a) {
- in >> a.fi >> a.se;
- return in;
- }
- const ll inf = (ll) 2e9;
- const ld pi = asin (1) * 2;
- const ld eps = 1e-8;
- const ll mod = (ll)1e9 + 7;
- const ll ns = 97;
- mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
- struct tree {
- vector<int> mx, mn;
- int size = 1, capacity;
- tree (vector<int>& v) {
- while ((1<<size) < sz (v)) ++size;
- ++size;
- size = (1<<size);
- capacity = (size>>1);
- mx = vector<int> (size, -inf);
- mn = vector<int> (size, inf);
- fr (i, sz (v)) mx[i + capacity] = mn[i + capacity] = v[i];
- for (int i = capacity - 1; i > 0; --i) {
- mx[i] = max (mx[i * 2], mx[i * 2 + 1]);
- mn[i] = min (mn[i * 2], mn[i * 2 + 1]);
- }
- }
- pii get (int cur, int left, int right, int l, int r) {
- pii ptt = {inf, -inf};
- if (cur >= size) return ptt;
- if (left > r || right < l) return ptt;
- if (l <= left && r >= right) return {mn[cur], mx[cur]};
- auto ptt1 = get (cur * 2, left, (left + right) / 2, l, r);
- auto ptt2 = get (cur * 2 + 1, (left + right) / 2 + 1, right, l, r);
- ptt.fi = min (ptt1.fi, ptt2.fi);
- ptt.se = max (ptt1.se, ptt2.se);
- return ptt;
- }
- inline int get (int l, int r) {
- auto ptt = get (1, 0, capacity - 1, l, r);
- return ptt.se - ptt.fi;
- }
- inline void set (int i, int x) {
- i += capacity;
- mn[i] = mx[i] = x;
- i >>= 1;
- while (i) {
- mn[i] = min (mn[i * 2], mn[i * 2 + 1]);
- mx[i] = max (mx[i * 2], mx[i * 2 + 1]);
- i >>= 1;
- }
- }
- };
- signed main () {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n = 1e5 + 20;
- vector<int> goo (n);
- fl (i, 1, n + 1) goo[i - 1] = i * i % 12345 + i * i * i % 23456;
- tree t (goo);
- int q;
- cin >> q;
- while (q--) {
- int x, y;
- cin >> x >> y;
- if (x > 0) {
- --x, --y;
- cout << t.get (x, y) << '\n';
- } else {
- x *= -1;
- --x;
- t.set (x, y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement