mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 17:48:48 +00:00
parent
1018034552
commit
1f2d950fb9
56
S2OJ/1505/1505.cpp
Normal file
56
S2OJ/1505/1505.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 100005;
|
||||
|
||||
int n, m, q, d_a[N], d_b[N];
|
||||
bool a[N], b[N];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cin >> b[i];
|
||||
}
|
||||
|
||||
if (a[1] != a[n]) d_a[0] = 1;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
d_a[i] = d_a[i - 1] + (a[i] != a[i + 1]);
|
||||
}
|
||||
|
||||
if (b[1] != b[m]) d_b[0] = 1;
|
||||
for (int i = 1; i <= m; i++) {
|
||||
d_b[i] = d_b[i - 1] + (b[i] != b[i + 1]);
|
||||
}
|
||||
|
||||
cin >> q;
|
||||
|
||||
while (q--) {
|
||||
std::pair<int, int> s, e;
|
||||
|
||||
cin >> s.first >> s.second >> e.first >> e.second;
|
||||
|
||||
cout << std::min({
|
||||
std::abs(d_a[s.first - 1] - d_a[e.first - 1]),
|
||||
d_a[n - 1] - d_a[std::max(s.first, e.first) - 1] + d_a[std::min(s.first, e.first) - 1],
|
||||
}) + std::min({
|
||||
std::abs(d_b[s.second - 1] - d_b[e.second - 1]),
|
||||
d_b[m - 1] - d_b[std::max(s.second, e.second) - 1] + d_b[std::min(s.second, e.second) - 1],
|
||||
})
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1505/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/data9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/data9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1505/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1505/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user