Thanks, TuSimple!

ime Limit: 1 Second      Memory Limit: 65536 KB


In the very first sentence of the very first problem, we would like to give our sincere thanks to TuSimple, the sponsor of this contest.

Founded in 2015, TuSimple is a global autonomous trucking solution company headquartered in San Diego, operating self-driving trucks out of Tucson, Arizona. TuSimple is now developing a commercial-ready Level 4 (SAE) fully-autonomous driving solution for the logistics industry. TuSimple's trucks are the first and only capable of self-driving from depot-to-depot and do so every day for its customers. The company is driven by a mission to increase safety, decrease transportation costs, and reduce carbon emissions.

Nowadays, the trucking industry is currently facing a shortage of 50000 drivers (which is expected to increase to 175000 by the end of 2024) and is approaching a 100 percent turnover rate per year with an average driver age of 49 years old. According to a PwC study, autonomous trucking technologies will reduce annual operating costs for a traditional average long-haul truck by 28 percent in 2025. TuSimple is aiming to transform the 740-billion U.S. trucking industry by cutting costs, reducing carbon emissions and eradicating some of the challenges currently faced by operators.

Building the industry's first 1000-meter perception system, TuSimple soon becomes the pioneer in the industry. As is known to us, 1000 meters can provide 35 seconds of reaction time on average at highway speeds, enabling the system to make the safest and most efficient driving decisions. Even in the adverse weather conditions, the perception system is still designed to identify objects and obstacles, ensuring the safety of both cargoes, trucks, and passers-by. On the other hand, TuSimple's latest proprietary AI is now capable of long-distance highway driving and complex surface street driving, which allows fully autonomous deliveries from one depot to another.

Despite their advanced technology and an enormous sense of mission in the industry, TuSimple shares the corporate culture of honesty, realistic, exploration and innovation among their employees from bottom to top, which allows them to attract more and more elites from all expertise to join and get involved. "Here's why a little-known autonomous trucking company is beating Tesla and Waymo in the race for driverless big rigs", commented by Business Insider.


The future of trucking is now!

As a manager of TuSimple, you are going to hold a dancing party for both the Development Department and the Marketing Department. There will be  gentlemen and  ladies in total and they are going to dance in pairs. After a careful investigation, we have already known that for each person, they like to dance with either a taller person or a person with smaller height. To simplify the problem, there are no two persons of the same height and people are only allowed to dance with a person of the opposite gender. In order to reserve a proper dancing field, you must calculate the maximum possible number of pairs of people dancing at the same time.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers  (), indicating the number of gentlemen and ladies.

The second line contains  integers  (,  for all ), indicating the height of each gentleman.

The third line contains  integers  (,  for all ), indicating the height of each lady.

The fourth line contains  integers  (), indicating the preference of each gentleman. If , it means gentleman prefers to dance with a lady of smaller height. Otherwise it indicates he prefers to have a taller dancing partner.

The fifth line contains  integers  (), indicating the preference of each lady. If , it means lady  prefers to dance with a gentleman of smaller height. Otherwise it indicates she prefers to have a taller dancing partner.

It's guaranteed that the sum of  and  of all test cases will not exceed  and  for all .

Output

For each test case output one line containing one integer, indicating the answer.

Sample Input

1
3 3
1 2 5
3 4 6
1 1 0
0 0 1

Sample Output

2

Hint

In the sample test case, the 1st gentleman can dance with the 2nd lady, and the 2nd gentleman can dance with the 1st lady.

分组遍利 

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
typedef long long ll;
ll m,n;
using namespace std;
int main()
{
    int t;
    long long ans;
    cin>>t;
    while(t--){
       set<ll>s;
       ans = 0;
       cin>>n>>m;
       vector<ll>man_0;
       vector<ll>man_1;
       vector<ll>woman_0;
       vector<ll>woman_1;
       vector<ll>a;
       vector<ll>b;
       for(int i = 0;i<n;i++){
            ll x;
            cin>>x;
            a.push_back(x);
       }
       for(int i = 0;i<m;i++){
            ll x;
            cin>>x;
            b.push_back(x);
       }
       for(int i = 0;i<n;i++){
            int x;
            cin>>x;
            if(x == 0){
                man_0.push_back(a[i]);
            }
            else{
                man_1.push_back(a[i]);
            }
       }
       for(int i = 0;i<m;i++){
            int x;
            cin>>x;
            if(x == 0){
                woman_0.push_back(b[i]);
            }
            else{
                woman_1.push_back(b[i]);
            }
       }
       sort(man_0.begin(),man_0.end());
       sort(man_1.begin(),man_1.end());
       sort(woman_0.begin(),woman_0.end());
       sort(woman_1.begin(),woman_1.end());
       vector<ll>::iterator  i;
       vector<ll>::iterator  j;
       vector<ll>::iterator k;
       ll L = 0;
       s.clear();
       k = woman_0.begin();
       L = 0;
       for(i = man_1.begin();i!=man_1.end();i++){
            j = upper_bound(k+L,woman_0.end(),*i);
            //cout << *j << endl;
            if(j!=woman_0.end()){
                L = j-k+1;
                if(!s.count(*j)){
                    ans++;
                    s.insert(*j);
                }
            }
       }
       //cout << ans << endl;
       s.clear();
       k = man_0.begin();
       L = 0;
       for(i = woman_1.begin();i!=woman_1.end();i++){
           j = upper_bound(k+L,man_0.end(),*i);
           if(j!= man_0.end()){
                if(!s.count(*j)){
                    L = j-k+1;
                    ans ++;
                    s.insert(*j);
                }
           }
        }
       cout<< ans <<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值