C 特殊距离

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<bits/stdc++.h>

using namespace std;

const int N = 1e6+10;
struct Point
{
int x, y;
} p[N];

bool cmp1(const Point &a, const Point &b) {
return a.x < b.x;
}

bool cmp2(const Point &a, const Point &b) {
return a.y < b.y;
}

int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);

int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i].x >> p[i].y;
}
sort(p + 1, p + n + 1, cmp1);
int max_dist = p[n].x - p[1].x;
sort(p + 1, p + n + 1, cmp2);
max_dist = max(max_dist, p[n].y - p[1].y);

int res = max_dist % 2 == 0 ? max_dist / 2 : max_dist / 2 + 1;
cout << res << endl;
return 0;
}

D 差分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<bits/stdc++.h>

using namespace std;
const int N = 5e5+10;

int n, m;
string s, t;

// 差分数组 sub[i] = cnt[i] - cnt[i - 1], cnt[0] = 0
int sub[N];
int cnt[N];

int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);

cin >> n >> m;
cin >> s >> t;
for (int i = 0; i < m; i++) {
int l, r;
cin >> l >> r;
sub[l]++;
sub[r + 1]--;
}
for (int i = 1; i <= n; i++) {
cnt[i] = cnt[i - 1] + sub[i];
}

for (int i = 1; i <= n; i++) {
if (cnt[i] % 2 == 1) {
s[i - 1] = t[i - 1];
}
}
cout << s << endl;


return 0;
}