253272026-02-19 10:59:54MatematikaTiltott pár (45 pont)cpp17Accepted 45/45206ms9812 KiB
#include <bits/stdc++.h>
using namespace std;

map<int, vector<int>> m;
map<pair<int,int>, int> volt;

int ki(vector<int>& x, vector<int>& y)
{
    int swapamount=0;
    if(x.size()>y.size())
    {
        for(int i=y.size()-1; i>=0; i--)
        {
            if(y[i]>x[swapamount])
            {
                swapamount++;
            }
        }
        return swapamount;
    }
    for(int i=0; i<x.size(); i++)
    {
        if(x[i]<y[y.size()-1-swapamount])
        {
            swapamount++;
        }
    }
    return swapamount;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, onlyin, onlyin2, q; cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> onlyin;
        m[onlyin].push_back(i);
    }
    cin >> q;
    for(int i=0; i<q; i++)
    {
        cin >> onlyin >> onlyin2;
        if(volt.find({onlyin, onlyin2})!=volt.end())
        {
            cout << volt[{onlyin, onlyin2}] << "\n";
            continue;
        }
        volt[{onlyin, onlyin2}]=ki(m[onlyin], m[onlyin2]);
        cout << volt[{onlyin, onlyin2}] << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base45/45
1Accepted0/01ms316 KiB
2Accepted0/02ms500 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/22ms564 KiB
8Accepted2/22ms316 KiB
9Accepted3/32ms456 KiB
10Accepted2/2197ms9132 KiB
11Accepted2/2187ms8956 KiB
12Accepted2/2200ms9812 KiB
13Accepted2/2206ms9288 KiB
14Accepted3/3180ms7592 KiB
15Accepted3/3178ms7544 KiB
16Accepted2/2187ms7480 KiB
17Accepted2/2180ms7604 KiB
18Accepted2/2173ms7600 KiB
19Accepted2/293ms3892 KiB
20Accepted2/243ms1332 KiB
21Accepted2/241ms1328 KiB
22Accepted2/243ms1332 KiB
23Accepted2/243ms1328 KiB