ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules, Teams

2019-10-30 13:03:21  阅读:506  来源: 互联网

标签:like Contest Rules after ICPC int th post highest


A. Berstagram

Polycarp recently signed up to a new social network Berstagram. He immediately published n posts there. He assigned numbers from 1 to n to all posts and published them one by one. So, just after publishing Polycarp's news feed contained posts from 1 to n — the highest post had number 1, the next one had number 2, ..., the lowest post had number n.

After that he wrote down all likes from his friends. Likes were coming consecutively from the 1-st one till the m-th one. You are given a sequence a1,a2,…,am (1≤aj≤n), where aj is the post that received the j-th like.

News feed in Berstagram works in the following manner. Let's assume the j-th like was given to post aj. If this post is not the highest (first) one then it changes its position with the one above. If aj is the highest post nothing changes.

For example, if n=3, m=5 and a=[3,2,1,3,3], then Polycarp's news feed had the following states:

before the first like: [1,2,3];
after the first like: [1,3,2];
after the second like: [1,2,3];
after the third like: [1,2,3];
after the fourth like: [1,3,2];
after the fifth like: [3,1,2].
Polycarp wants to know the highest (minimum) and the lowest (maximum) positions for each post. Polycarp considers all moments of time, including the moment "before all likes".

Input
The first line contains two integer numbers n and m (1≤n≤105, 1≤m≤4⋅105) — number of posts and number of likes.

The second line contains integers a1,a2,…,am (1≤aj≤n), where aj is the post that received the j-th like.

Output
Print n pairs of integer numbers. The i-th line should contain the highest (minimum) and the lowest (maximum) positions of the i-th post. You should take into account positions at all moments of time: before all likes, after each like and after all likes. Positions are numbered from 1 (highest) to n (lowest).

Examples input Copy
3 5
3 2 1 3 3
output Copy
1 2
2 3
1 3
input Copy
10 6
7 3 5 7 3 6
output Copy
1 2
2 3
1 3
4 7
4 5
6 7
5 7
8 8
9 9
10 10
思路:定义两个数组,分别存放不断改变的当前数和某数的位置。然后模拟。QAQ 
#include<bits/stdc++.h>

using namespace std;
#define int long long
#define N 1000500
struct str{
    int L,R;
}st[N];
int arr[N];
int a[N];// 当前的数 
int b[N];// 某数的位置 
signed main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        st[i].L=i;
        st[i].R=i;
        a[i]=i;
        b[i]=i;
    }
    for(int i=1;i<=m;i++)
        scanf("%lld",&arr[i]);
    for(int i=1;i<=m;i++){
        if(b[arr[i]]!=1){
            int weizhi=b[arr[i]];
            int temp=a[weizhi-1];//前面一个数
            swap(a[weizhi],a[weizhi-1]); 
            b[arr[i]]=b[arr[i]]-1;
            b[temp]=b[temp]+1;
            st[arr[i]].L=min(st[arr[i]].L,b[arr[i]]);
            st[arr[i]].R=max(st[arr[i]].R,b[arr[i]]);
            st[temp].L=min(st[temp].L,b[temp]);
            st[temp].R=max(st[temp].R,b[temp]);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<st[i].L<<" "<<st[i].R<<'\n';
    }
    return 0;
}

 

 

标签:like,Contest,Rules,after,ICPC,int,th,post,highest
来源: https://www.cnblogs.com/pengge666/p/11764217.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有