結果
| 問題 | No.3605 Grand Cross |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-31 22:13:02 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 115 ms / 2,000 ms |
| + 608µs | |
| コード長 | 2,150 bytes |
| 記録 | |
| コンパイル時間 | 2,790 ms |
| コンパイル使用メモリ | 343,644 KB |
| 実行使用メモリ | 22,580 KB |
| 最終ジャッジ日時 | 2026-07-31 22:13:14 |
| 合計ジャッジ時間 | 10,756 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 49 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
#ifdef Doludu
template <typename T>
ostream& operator << (ostream &o, vector <T> vec) {
o << "{"; int f = 0;
for (T i : vec) o << (f++ ? " " : "") << i;
return o << "}";
}
void bug__(int c, auto ...a) {
cerr << "\e[1;" << c << "m";
(..., (cerr << a << " "));
cerr << "\e[0m" << endl;
}
#define bug_(c, x...) bug__(c, __LINE__, "[" + string(#x) + "]", x)
#define bug(x...) bug_(32, x)
#define bugv(x...) bug_(36, vector(x))
#define safe bug_(33, "safe")
#else
#define bug(x...) void(0)
#define bugv(x...) void(0)
#define safe void(0)
#endif
const int mod = 998244353, N = 300005;
void solve() {
int n, m;
cin >> n >> m;
vector <int> a(n), b(m), c(n), d(m);
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) cin >> b[i];
for (int i = 0; i < n; ++i) cin >> c[i], --c[i];
for (int i = 0; i < m; ++i) cin >> d[i], --d[i];
ll ans = -1;
auto solve = [&]() {
vector <vector <pair <int, ll>>> eve(n + m);
vector <ll> pre1(n + 1), pre2(m + 1);
for (int i = 1; i <= n; ++i) pre1[i] = pre1[i - 1] + a[i - 1];
for (int i = 1; i <= m; ++i) pre2[i] = pre2[i - 1] + b[i - 1];
for (int i = 0; i * 2 < n; ++i) {
eve[c[i]].emplace_back(i, pre1[2 * i + 1]);
}
for (int i = 0; i < m; ++i) {
int mn = min(i, m - i - 1);
auto it = lower_bound(all(eve[d[i]]), pair(mn + 1, -1ll));
if (it == eve[d[i]].begin()) continue;
auto [cur, val] = *prev(it);
ans = max(ans, val + pre2[i + cur + 1] - pre2[i - cur]);
}
};
solve();
reverse(all(a)), reverse(all(c));
solve();
reverse(all(a)), reverse(all(c));
swap(a, b), swap(n, m), swap(c, d);
solve();
reverse(all(a)), reverse(all(c));
solve();
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
}