結果

問題 No.3436 [Cherry 8th Tune B] この夏に何が起こるかな?
コンテスト
ユーザー abc864197532
提出日時 2026-01-23 22:29:07
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 437 ms / 4,000 ms
コード長 2,775 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,605 ms
コンパイル使用メモリ 361,516 KB
実行使用メモリ 19,340 KB
最終ジャッジ日時 2026-01-23 22:30:59
合計ジャッジ時間 22,555 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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 = 1 << 20;

void solve() {
    int n, m, k; ll p;
    cin >> n >> m >> k >> p;
    auto read = [&](int cnt) {
        vector <pair <ll, int>> a(cnt);
        for (int i = 0; i < cnt; ++i) cin >> a[i].first, a[i].second = i;
        vector <vector <pair <ll, int>>> pos(k);
        for (int i = 0, x; i < cnt; ++i) cin >> x, pos[--x].pb(a[i]);
        sort(all(a));
        for (int i = 0; i < k; ++i) sort(all(pos[i]));
        return pair(a, pos);
    };
    auto [aa, a] = read(n);
    auto [bb, b] = read(m);
    vector <ll> s(k);
    for (int i = 0; i < k; ++i) cin >> s[i];
    auto get = [&](vector <pair <ll, int>> &vec, ll x) {
        return lower_bound(all(vec), pair(x + 1, -1)) - vec.begin();
    };
    auto query = [&](ll x) {
        ll ans = 0;
        for (int i = 0; i < k; ++i) {
            for (auto [cur, id] : a[i]) {
                ans += get(bb, x - cur) - get(b[i], x - cur) + get(b[i], x + s[i] - cur);
            }
        }
        return ans;
    };
    ll l = 0, r = 1ll << 32;
    while (r - l > 1) {
        ll mid = l + r >> 1;
        if (query(mid) < p) l = mid;
        else r = mid;
    }
    ll res = r;
    map <pii, int> mp;
    for (int i = 0; i < k; ++i) {
        for (auto [x, id] : b[i]) {
            mp[{x, i}] = id;
        }
    }
    pii ans(-1, -1);
    for (int i = 0; i < k; ++i) for (auto [x, id] : a[i]) {
        auto it = mp.lower_bound({res - x, -1});
        while (true) {
            if (it == mp.end() || (it->first).first != res - x) break;
            if ((it->first).second == i) {
                it = next(it);
            } else {
                ans = {id, it->second};
                break;
            }
        }
        if (mp.count({res + s[i] - x, i})) {
            ans = {id, mp[{res + s[i] - x, i}]};
        }
    }
    bug(res);
    cout << ans.first + 1 << " " << ans.second + 1 << "\n";
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
0