日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Little Elephant and Shifts(CF-220C)

發布時間:2025/3/17 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Little Elephant and Shifts(CF-220C) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

The Little Elephant has two permutations a and b of length n, consisting of numbers from 1 to n, inclusive. Let's denote the i-th (1?≤?i?≤?n) element of the permutation a as ai, the j-th (1?≤?j?≤?n) element of the permutation b — as bj.

The distance between permutations a and b is the minimum absolute value of the difference between the positions of the occurrences of some number in a and in b. More formally, it's such minimum |i?-?j|, that ai?=?bj.

A cyclic shift number i (1?≤?i?≤?n) of permutation b consisting from n elements is a permutation bibi?+?1... bnb1b2... bi?-?1. Overall a permutation has n cyclic shifts.

The Little Elephant wonders, for all cyclic shifts of permutation b, what is the distance between the cyclic shift and permutation a?

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the size of the permutations. The second line contains permutation a as n distinct numbers from 1 to n, inclusive. The numbers are separated with single spaces. The third line contains permutation b in the same format.

Output

In n lines print n integers — the answers for cyclic shifts. Print the answers to the shifts in the order of the shifts' numeration in permutation b, that is, first for the 1-st cyclic shift, then for the 2-nd, and so on.

Examples

Input

2
1 2
2 1

Output

1
0

Input

4
2 1 3 4
3 4 2 1

Output

2
1
0
1

題意:給出兩個長度為 n 的序列 a 、b,定義距離為:若 a[i]==b[i],則 dis=|i-j|,現在要進行 n-1 次操作,每次將 b 序列進行循環左移,要求輸出初始序列以及每次左移后的序列的最小的 dis

思路:

若 b[j] 在 a[i] 的左邊,那么每次移動,dis+1,反之,若 b[j] 在 a[i] 的右邊,每次移動,dis-1

因此使用 multiset 模擬每次挪動的過程,統計每一次左移一共加了多少、減了多少,然后在每次的答案中找大于 0 中最小的,小于 0 中最大的,兩者再取最小

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<bitset> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 1000000+5; const int dx[] = {-1,1,0,0,-1,-1,1,1}; const int dy[] = {0,0,-1,1,-1,1,-1,1}; using namespace std;multiset<int> st; int bucket[N],b[N]; int main(){int n,x;scanf("%d",&n);for(int i=1;i<=n;i++){int x;scanf("%d",&x);bucket[x]=i;}for(int i=1;i<=n;i++){scanf("%d",&b[i]);int pos=i-bucket[b[i]];st.insert(pos);}multiset<int>::iterator it;for(int i=0;i<n;i++){it=st.lower_bound(i);//尋找位置int res=INF;if(it!=st.end()){int temp=(*it)-i;res=min(res,temp);}if(it!=st.begin()){it--;int temp=i-(*it);res=min(res,temp);}printf("%d\n",res);int pos=b[i+1];int temp=i+1-bucket[pos];it=st.find(temp);st.erase(it);//刪除第一個temp+=n;st.insert(temp);//插入到最后}return 0; }

?

總結

以上是生活随笔為你收集整理的Little Elephant and Shifts(CF-220C)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 精品久久久久久久久久久久久久久久 | 日韩欧美一区二区区 | 成人h动漫精品一区二区下载 | 久久精品99北条麻妃 | 国产成人av电影 | 成年人小视频 | 日本黄页网站免费大全 | 自拍欧美日韩 | 色综合久久88色综合天天 | av免费网站 | 亚洲午夜精品久久久久久人妖 | 91香蕉国产在线观看 | 日韩av中文在线观看 | www一区二区三区 | 日本激情视频网站 | 操碰人人 | 国产视频欧美视频 | 丰满少妇一区二区三区专区 | 亚洲欧美激情在线观看 | 久久久久夜夜夜精品国产 | 欧美午夜一区二区 | 亚洲少妇15p| 国产内谢 | xxx精品| 天堂资源最新在线 | 欧美一级在线视频 | 不用播放器av | 免费三片在线观看网站v888 | 另类激情视频 | 大桥未久av一区二区三区中文 | 男人天堂av网站 | 求欧美精品网址 | 又大又长粗又爽又黄少妇视频 | 国产精品100 | 青青青国产 | 国产大片一区二区三区 | 我我色综合 | 色88久久久久高潮综合影院 | 久久不卡视频 | 99视频在线免费 | 青青草视频免费观看 | 性欧美一区二区三区 | 国产av精国产传媒 | 女同性做爰全过程 | 国产精品久久久久久一区 | 一个色在线 | 午夜激情视频在线播放 | 91黄版| 国产精品久久久久久久久晋中 | 粗大挺进潘金莲身体在线播放 | 黑人巨大猛烈捣出白浆 | 国产精品一区二区免费视频 | 麻豆av在线看 | 日本高清不卡二区 | 欧美在线观看视频一区二区 | 久久高清国产 | 国产99久久久欧美黑人 | 中文字幕无码精品亚洲 | 精品嫩模一区二区三区 | 国产特黄 | 久久久久久久久久影院 | 国产蜜臀在线 | 91在线一区 | aaaaa毛片 | 国产精品美女久久久网av | 国产15页| 99碰碰 | 成人国产精品久久 | 99国产视频| 日日操夜夜 | 女儿的朋友5中汉字晋通话 欧美成人免费高清视频 | 婷婷俺来也| 亚洲最大av网站 | 欧美综合在线视频 | 懂色av中文一区二区三区天美 | 天天操夜夜操 | 91精品国产自产91精品 | 欧美色图一区二区 | 日韩视频一区二区三区在线播放免费观看 | 91中文字幕在线播放 | 日韩视频一区二区三区四区 | 秋霞影院午夜 | av黄色免费在线观看 | 九九九九九九精品 | 亚洲熟妇av乱码在线观看 | 欧美性猛交xx乱大交 | 反差在线观看免费版全集完整版 | 久久美利坚 | 亚洲婷婷av| 欧美视频在线观看视频 | 99久久99久久精品国产片果冻 | 日日草日日干 | 性欧美8khd高清极品 | 2017狠狠干 | 亚洲涩网 | 天天操妹子 | 亚洲精品无 | 我要色综合天天 | 免费在线不卡av |