提交时间:2023-08-14 15:11:48
运行 ID: 98330
#include<bits/stdc++.h> using namespace std; #ifdef IAKIOI #define cin fin ifstream cin("in.txt"); #endif #define ll long long constexpr int N = 2e5 + 5; int x[N], y[N]; inline int f(int x, int y) { return abs(x) + abs(y); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; for (int i = 1; i < n; ++i) { cin >> x[i] >> y[i]; } while (m--) { int op, a, b, c, d; cin >> op >> a >> b >> c; if (op == 1) { x[a] = b, y[a] = c; } else { cin >> d; if (max(a, b) > max(c, d)) swap(a, c), swap(b, d); int xa = a, ya = b, xb = a, yb = b; ll s1 = 0, s2 = 0; for (int i = max(a, b); i < max(c, d); ++i) { s1 += min(f(i - xa, x[i] - ya), f(i - xb, x[i] - yb)) + 1; s2 += min(f(y[i] - xa, i - ya), f(y[i] - xb, i - yb)) + 1; xa = i + 1, ya = x[i]; xb = y[i], yb = i + 1; } cout << min(s1 + f(xa - c, ya - d), s2 + f(xb - c, yb - d)) << '\n'; } } return 0; }