Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- int main(){
- Faster;
- int t;
- cin>>t;
- while(t--)
- {
- int n;
- cin>>n;
- vector<int>a(n),b(n),ta(n),tb(n);
- for(int i=0;i<n;i++){
- cin>>a[i];
- ta[i]=a[i];
- }
- for(int i=0;i<n;i++) {
- cin>>b[i];
- tb[i]=b[i];
- }
- // for(ll i=0;i<n;i++) {
- // cout<<ta[i]<<" ";
- // }
- sort(ta.begin(),ta.end());
- sort(tb.begin(),tb.end());
- ta.erase(std::unique(ta.begin(),ta.end(),ta.end()));
- tb.erase(std::unique(tb.begin(),tb.end(),tb.end()));
- for(int i=0;i<n;i++) {
- a[i]=lower_bound(ta.begin(),ta.end(),a[i])-ta.begin();
- }
- for(int i=0;i<n;i++) {
- b[i]=lower_bound(tb.begin(),tb.end(),b[i])-tb.begin();
- }
- int temp=0,ans=0;
- vector<int>p(n),q(n),r,crr(n);
- for(int i=0;i<n;i++)
- {
- crr[a[i]]=b[i];
- p[i]=a[i]+b[i];
- q[b[i]]=i;
- }
- for(int i=0;i<n;i++)
- {
- r.insert(upper_bound(r.begin(),r.end(),crr[i]),crr[i]);
- p[q[crr[i]]]-=lower_bound(r.begin(),r.end(),crr[i])-r.begin();
- }
- for(auto i:p)
- {
- temp=max(i,temp);
- }
- for(auto i:p)
- {
- ans+=(i==temp);
- }
- cout<<ans<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment