Educational Codeforces Round 80 (Rated for Div. 2) E. Messenger Simulator

烈酒焚心 提交于 2020-01-17 00:10:55

E. Messenger Simulator

传送门

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}
 
template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}
 
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define MAXN 300013
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
 
int N, M;
int arr[MAXN];
pii ans[MAXN];
bitset<MAXN> vis;
int val[MAXN];
ordered_set<int> vals;
 
int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N >> M;
    FOR(i, 0, M)
    {
        cin >> arr[i]; arr[i]--;
        vis[arr[i]] = true;
    }
    FOR(i, 0, N)
    {
        ans[i].fi = (vis[i] ? 0 : i);
        ans[i].se = i;
        val[i] = i;
        vals.insert(i);
    }
    FOR(i, 0, M)
    {
        int idx = arr[i];
        ckmax(ans[idx].se, vals.order_of_key(val[idx]));
        vals.erase(val[idx]);
        val[idx] = -i - 1;
        vals.insert(val[idx]);
    }
    FOR(i, 0, N)
    {
        ckmax(ans[i].se, vals.order_of_key(val[i]));
    }
   
    FOR(i, 0, N)
    {
        cout << ans[i].fi + 1 << ' ' << ans[i].se + 1 << '\n';
    }
    return 0;
   
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!