Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define F first
- #define S second
- #define ll int
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- ll i,j,a,b,n,m;
- cin>>n;
- vector<pair<ll,ll> >v;
- map<pair<ll,ll>,ll>mp;
- for(i=1; i<=n; i++)
- {
- cin>>a>>b;
- v.emplace_back(a,b);
- }
- cin>>m;
- for(i=1; i<=m; i++)
- {
- cin>>a>>b;
- mp[{a,b}]=i;
- }
- ll pre,pos,ans=0;
- i=0;
- while(i<n)
- {
- if(mp[{v[i].F,v[i].S}])
- {
- pre=mp[{v[i].F,v[i].S}];
- i++;
- ll cnt=1;
- while(i<n)
- {
- pos=mp[{v[i].F,v[i].S}];
- if(pre+1==pos)
- {
- cnt++;
- }
- else break;
- pre=pos;
- i++;
- }
- i--;
- ans=max(ans,cnt);
- }
- i++;
- }
- i=0;
- while(i<n)
- {
- if(mp[{v[i].F,v[i].S}])
- {
- pre=mp[{v[i].F,v[i].S}];
- i++;
- ll cnt=1;
- while(i<n)
- {
- pos=mp[{v[i].F,v[i].S}];
- if(pre==pos+1)
- {
- cnt++;
- }
- else break;
- pre=pos;
- i++;
- }
- i--;
- ans=max(ans,cnt);
- }
- i++;
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement