Pair of Topics (codeforces 1324D)
Problem Link:https://vjudge.net/problem/CodeForces-1324D/origin
SOLUTION:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<ll,ll> node;
typedef tree<node, null_type, less<node>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ordered_set s;
ll n;
cin>>n;
ll a[n+2];
ll b[n+2];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
ll cnt=0;
for(int i=0;i<n;i++){
cnt+=i-s.order_of_key(node(b[i]-a[i],n));
s.insert(node(a[i]-b[i],i));
}
cout<<cnt<<endl;
}
No comments