Submission #71865825
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
using namespace std;
using ll = long long;
const ll INF = 1e18;
struct Node {
ll U_max, U_min;
ll V_max, V_min;
Node() : U_max(-INF), U_min(INF), V_max(-INF), V_min(INF) {}
Node(ll u, ll v) : U_max(u), U_min(u), V_max(v), V_min(v) {}
};
Node merge(const Node& l, const Node& r) {
Node res;
res.U_max = max(l.U_max, r.U_max);
res.U_min = min(l.U_min, r.U_min);
res.V_max = max(l.V_max, r.V_max);
res.V_min = min(l.V_min, r.V_min);
return res;
}
vector<Node> tree;
vector<ll> U, V;
int n;
void build(int p, int l, int r) {
if (l == r) {
tree[p] = Node(U[l], V[l]);
return;
}
int mid = (l + r) / 2;
build(p * 2, l, mid);
build(p * 2 + 1, mid + 1, r);
tree[p] = merge(tree[p * 2], tree[p * 2 + 1]);
}
void update(int p, int l, int r, int idx, ll u, ll v) {
if (l == r) {
tree[p] = Node(u, v);
return;
}
int mid = (l + r) / 2;
if (idx <= mid) update(p * 2, l, mid, idx, u, v);
else update(p * 2 + 1, mid + 1, r, idx, u, v);
tree[p] = merge(tree[p * 2], tree[p * 2 + 1]);
}
Node query(int p, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) return tree[p];
int mid = (l + r) / 2;
Node res;
if (ql <= mid) res = merge(res, query(p * 2, l, mid, ql, qr));
if (qr > mid) res = merge(res, query(p * 2 + 1, mid + 1, r, ql, qr));
return res;
}
int main() {
scanf("%d", &n);
int q;
scanf("%d", &q);
U.resize(n + 1);
V.resize(n + 1);
for (int i = 1; i <= n; i++) {
ll x, y;
scanf("%lld%lld", &x, &y);
U[i] = x + y;
V[i] = x - y;
}
tree.resize(4 * n);
build(1, 1, n);
while (q--) {
int t;
scanf("%d", &t);
if (t == 1) {
int i; ll x, y;
scanf("%d%lld%lld", &i, &x, &y);
update(1, 1, n, i, x + y, x - y);
}
else {
int l, r; ll x, y;
scanf("%d%d%lld%lld", &l, &r, &x, &y);
Node nd = query(1, 1, n, l, r);
ll u = x + y, v = x - y;
ll d1 = max(u - nd.U_min, nd.U_max - u);
ll d2 = max(v - nd.V_min, nd.V_max - v);
printf("%lld\n", max(d1, d2));
}
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
F - Manhattan Christmas Tree 2 |
| User |
alexxy |
| Language |
C++23 (GCC 15.2.0) |
| Score |
500 |
| Code Size |
2453 Byte |
| Status |
AC |
| Exec Time |
185 ms |
| Memory |
31772 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3820 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3656 KiB |
| 01_random_00.txt |
AC |
163 ms |
31500 KiB |
| 01_random_01.txt |
AC |
174 ms |
31600 KiB |
| 01_random_02.txt |
AC |
174 ms |
31660 KiB |
| 01_random_03.txt |
AC |
178 ms |
31772 KiB |
| 01_random_04.txt |
AC |
182 ms |
31596 KiB |
| 01_random_05.txt |
AC |
182 ms |
31536 KiB |
| 01_random_06.txt |
AC |
182 ms |
31544 KiB |
| 01_random_07.txt |
AC |
184 ms |
31420 KiB |
| 01_random_08.txt |
AC |
185 ms |
31596 KiB |
| 01_random_09.txt |
AC |
184 ms |
31596 KiB |
| 01_random_10.txt |
AC |
139 ms |
31660 KiB |
| 01_random_11.txt |
AC |
140 ms |
31600 KiB |
| 01_random_12.txt |
AC |
144 ms |
31600 KiB |
| 01_random_13.txt |
AC |
139 ms |
31620 KiB |
| 01_random_14.txt |
AC |
140 ms |
31616 KiB |
| 01_random_15.txt |
AC |
53 ms |
3812 KiB |
| 01_random_16.txt |
AC |
99 ms |
31556 KiB |
| 01_random_17.txt |
AC |
145 ms |
31772 KiB |
| 01_random_18.txt |
AC |
143 ms |
31772 KiB |
| 01_random_19.txt |
AC |
139 ms |
31608 KiB |
| 01_random_20.txt |
AC |
139 ms |
31616 KiB |
| 01_random_21.txt |
AC |
140 ms |
31596 KiB |