Submission #68937189


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

using LL = long long;
#define endl '\n'
using db = double;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int Q;
    cin >> Q;
    vector<LL> op(Q + 1);
    vector<LL> A(Q + 10), B(Q + 10);
    vector<LL> nxt(Q + 10, Q + 9);
    for (int i = 1; i <= Q; ++i)
    {
        // cerr << "i = " << i << endl;
        cin >> op[i];
        if (op[i] == 1)
        {
            cin >> A[i];
            nxt[i] = nxt[A[i]];
            nxt[A[i]] = i;
        }
        else
        {
            // for (int j = 0; j <= Q; ++j)
            //     cerr << "j = " << j << " nxt[j] = " << nxt[j] << endl;
            cin >> A[i] >> B[i];
            if (nxt[A[i]] == B[i] || nxt[B[i]] == A[i])
            {
                cout << 0 << endl;
                continue;
            }
            int now1 = nxt[A[i]], now2 = nxt[B[i]];
            LL ans1 = 0, ans2 = 0;
            while (1)
            {
                if (now1 == B[i])
                    break;
                else
                {
                    ans1 += now1;
                    now1 = nxt[now1];
                }

                if (now2 == A[i])
                    break;
                else
                {
                    ans2 += now2;
                    now2 = nxt[now2];
                }
            }
            if (now1 == B[i])
            {
                nxt[A[i]] = B[i];
                cout << ans1 << endl;
            }
            else
            {
                nxt[B[i]] = A[i];
                cout << ans2 << endl;
            }
        }
    }
}

Submission Info

Submission Time
Task F - Erase between X and Y
User hialine
Language C++ 20 (gcc 12.2)
Score 525
Code Size 1837 Byte
Status AC
Exec Time 72 ms
Memory 18744 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 36
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3468 KiB
00_sample_01.txt AC 1 ms 3468 KiB
00_sample_02.txt AC 1 ms 3424 KiB
01_random_00.txt AC 63 ms 18648 KiB
01_random_01.txt AC 72 ms 18580 KiB
01_random_02.txt AC 71 ms 18612 KiB
01_random_03.txt AC 71 ms 18624 KiB
01_random_04.txt AC 70 ms 18504 KiB
01_random_05.txt AC 70 ms 18500 KiB
01_random_06.txt AC 70 ms 18632 KiB
01_random_07.txt AC 68 ms 18504 KiB
01_random_08.txt AC 68 ms 18620 KiB
01_random_09.txt AC 67 ms 18616 KiB
01_random_10.txt AC 65 ms 18576 KiB
01_random_11.txt AC 63 ms 18592 KiB
01_random_12.txt AC 61 ms 18588 KiB
01_random_13.txt AC 60 ms 18564 KiB
01_random_14.txt AC 57 ms 18568 KiB
01_random_15.txt AC 54 ms 18576 KiB
01_random_16.txt AC 52 ms 18620 KiB
01_random_17.txt AC 49 ms 18588 KiB
01_random_18.txt AC 47 ms 18572 KiB
01_random_19.txt AC 44 ms 18620 KiB
01_random_20.txt AC 49 ms 18668 KiB
02_random2_00.txt AC 51 ms 18644 KiB
02_random2_01.txt AC 46 ms 18600 KiB
02_random2_02.txt AC 44 ms 18644 KiB
02_random2_03.txt AC 41 ms 18744 KiB
02_random2_04.txt AC 39 ms 18648 KiB
03_handmade_00.txt AC 1 ms 3344 KiB
03_handmade_01.txt AC 40 ms 18596 KiB
03_handmade_02.txt AC 33 ms 18612 KiB
03_handmade_03.txt AC 41 ms 18564 KiB
03_handmade_04.txt AC 60 ms 18568 KiB
03_handmade_05.txt AC 56 ms 18576 KiB
03_handmade_06.txt AC 54 ms 18596 KiB