Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- int n;
- vector <int> a,b, dmin, dmax;
- bool sh=0;
- void bsmin(int i){
- int L = -1, R = n - 1, M;//R - ans
- while (L + 1 < R){
- M = (L + R) / 2;
- if (b[M] >= a[i]){
- R = M;
- }
- else{
- L = M;
- }
- }
- dmin[i] = b[R] - a[i];
- }
- void bsmax(int i){
- int L = i, R = n - 1, M; //L-ans
- while (L + 1 < R){
- M = (L + R) / 2;
- if (b[M] >= a[M+1]){
- L = M;
- }
- else{
- R = M;
- }
- }
- dmax[i] = b[L + 1] - a[i];
- }
- void slv(){
- for (int i = 0; i < n; ++i){
- //dmin
- if (i == 0){
- dmin[i] = b[0] - a[0];
- }
- else{
- bsmin(i);
- }
- //dmax
- if (i == n - 1){
- dmax[i] = b[n - 1] - a[n - 1];
- }
- else if (b[i] < a[i + 1]){
- dmax[i] = b[i] - a[i];
- }
- else{
- bsmax(i);
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int t=1;
- if (!sh) cin>>t;
- for (int go = 0; go < t; ++go){
- cin>>n;
- a.resize(n); for (int &i: a) cin>>i;
- b.resize(n); for (int &i: b) cin>>i;
- dmin.resize(n);
- dmax.resize(n);
- slv();
- cv(dmin);
- cv(dmax);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement