結果

問題 No.3126 Dual Query Problem
ユーザー テナガザル
提出日時 2025-04-25 21:35:41
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 413 ms / 2,000 ms
コード長 1,269 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 116,316 KB
実行使用メモリ 10,992 KB
最終ジャッジ日時 2025-06-20 02:40:50
合計ジャッジ時間 16,155 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int n, q;
    cin >> n >> q;
    vector<int> used(q + 5);
    used[0] = used[1] = 1;
    int now = 1;
    map<int, int> mp;
    mp[0] = 1;
    used[1] = 1;
    int cnt = 0;
    vector<int> t, p, x;
    for (int i = 0; i < n; ++i)
    {
        int v;
        cin >> v;
        if (mp.find(v) != mp.end())
        {
            t.push_back(2);
            p.push_back(mp[v]);
            x.push_back(0);
            ++cnt;
        }
        else
        {
            t.push_back(1);
            while (used[now]) ++now;
            p.push_back(now);
            used[now] = 1;
            ++cnt;
            mp[v] = now;
            x.push_back(v);
            t.push_back(2);
            p.push_back(now);
            x.push_back(v);
            ++cnt;
        }
    }
    if (cnt > q)
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    while (cnt++ < q)
    {
        t.push_back(1);
        p.push_back(1);
        x.push_back(1);
    }
    for (int i = 0; i < q; ++i)
    {
        cout << t[i] << ' ';
        cout << p[i];
        if (t[i] == 1) cout << ' ' << x[i] << endl;
        else cout << endl;
    }
}
0