Problem:
Problem C
Distribution Center
The factory of the Impractically Complicated Products Corporation has many manufacturing lines and the same number of corresponding storage rooms. The same number of conveyor lanes are laid out in parallel to transfer goods from manufacturing lines directly to the corresponding storage rooms. Now, they plan to install a number of robot arms here and there between pairs of adjacent conveyor lanes so that goods in one of the lanes can be picked up and released down on the other, and also in the opposite way. This should allow mixing up goods from different manufacturing lines to the storage rooms.
Depending on the positions of robot arms, the goods from each of the manufacturing lines can only be delivered to some of the storage rooms. Your task is to find the number of manufacturing lines from which goods can be transferred to each of the storage rooms, given the number of conveyor lanes and positions of robot arms.
Input
The input consists of a single test case, formatted as follows.
$n$ $m$
$x_1$ $y_1$
...
$x_m$ $y_m$
An integer $n$ ($2 \leq n \leq 200000$) in the first line is the number of conveyor lanes. The lanes are numbered from 1 to $n$, and two lanes with their numbers differing with 1 are adjacent. All of them start from the position $x = 0$ and end at $x = 100000$. The other integer $m$ ($1 \leq m < 100000$) is the number of robot arms.
The following $m$ lines indicate the positions of the robot arms by two integers $x_i$ ($0 < x_i < 100000$) and $y_i$ ($1 \leq y_i < n$). Here, $x_i$ is the
x
-coordinate of the $i$-th robot arm, which can pick goods on either the lane $y_i$ or the lane $y_i + 1$ at position $x = x_i$, and then release them on the other at the same
x
-coordinate.
You can assume that positions of no two robot arms have the same $x$-coordinate, that is, $x_i \ne x_j$ for any $i \ne j$.
Figure C.1. Illustration of Sample Input 1
Output
Output $n$ integers separated by a space in one line. The $i$-th integer is the number of the manufacturing lines from which the storage room connected to the conveyor lane $i$ can accept goods.
Sample Input 1
4 3
1000 1
2000 2
3000 3
Sample Output 1
2 3 4 4
Sample Input 2
4 3
1 1
3 2
2 3
Sample Output 2
2 4 4 2

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
	int n,m;cin >> n >> m;
	vector<pair<int,int>> xy(m);
	for (int i = 0; i < m; i++){
		int x,y;cin >> x >> y;
		y--;
		xy[i] = {x,y};
	}

	vector<int> ans(n,1);
	vector<int> bet(n-1,0);

	sort(xy.begin(),xy.end());

	for (auto [x,y]: xy){
		int k = ans[y] + ans[y+1] - bet[y];
		ans[y] = k,ans[y+1] = k,bet[y] = k;
	}
	for (int i = 0; i < n; i++)cout << ans[i] << " \n"[i==n-1];
}
accuracy: 1
time_ms: 40
memory_kb: 5460
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;

class UnionFind
{
public:

	UnionFind() = default;

	/// @brief Union-Find 木を構築します。
	/// @param n 要素数
	explicit UnionFind(size_t n)
		: m_parents(n)
		, m_sizes(n, 1)
	{
		std::iota(m_parents.begin(), m_parents.end(), 0);
	}

	/// @brief 頂点 i の root のインデックスを返します。
	/// @param i 調べる頂点のインデックス
	/// @return 頂点 i の root のインデックス
	int find(int i)
	{
		if (m_parents[i] == i)
		{
			return i;
		}

		// 経路圧縮
		return (m_parents[i] = find(m_parents[i]));
	}

	/// @brief a のグループと b のグループを統合します。
	/// @param a 一方のインデックス
	/// @param b 他方のインデックス
	void merge(int a, int b)
	{
		a = find(a);
		b = find(b);

		if (a != b)
		{
			m_sizes[a] += m_sizes[b];
			m_parents[b] = a;
		}
	}

	/// @brief a と b が同じグループに属すかを返します。
	/// @param a 一方のインデックス
	/// @param b 他方のインデックス
	/// @return a と b が同じグループに属す場合 true, それ以外の場合は false
	bool connected(int a, int b)
	{
		return (find(a) == find(b));
	}

	/// @brief i が属するグループの要素数を返します。
	/// @param i インデックス
	/// @return i が属するグループの要素数
	int size(int i)
	{
		return m_sizes[find(i)];
	}

private:

	// m_parents[i] は i の 親,
	// root の場合は自身が親
	std::vector<int> m_parents;

	// グループの要素数 (root 用)
	// i が root のときのみ, m_sizes[i] はそのグループに属する要素数を表す
	std::vector<int> m_sizes;
};

int main(){
    int n,m;cin >> n >> m;
    vector<pair<int,int>> xy(m);
    for (int i = 0; i < m; i++){
        int x,y;cin >> x >> y;
        y--;
        xy[i] = {x,y};
    }
    sort(xy.begin(),xy.end());

    UnionFind d(n);

    vector<int> ans(n,1);
    for (int i = 0; i < m; i++){
        auto [x,y] = xy[i];
        d.merge(y,y+1);
        ans[y] = d.size(y);
        ans[y+1] = d.size(y);
    }

    for (int i = 0; i < n; i++)cout << ans[i] << " \n"[i == n-1];
}
accuracy: 0.19444444444444445
time_ms: 40
memory_kb: 4776
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

ll mod = 998244353;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if(argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }
    ll n, m;
    cin >> n >> m;
    vector<a2> v(m);
    vector<a2> ans(n);
    for(auto& x : v) {
        cin >> x[0] >> x[1];
    }
    sort(v.begin(), v.end());

    for(int i = 0; i < n; i++) {
        ans[i] = {i + 1, i + 1};
    }

    for(auto [_, y] : v) {
        ll mn = min(ans[y - 1][0], ans[y][0]);
        ll mx = max(ans[y - 1][1], ans[y][1]);
        ans[y - 1] = {mn, mx};
        ans[y] = {mn, mx};
    }

    for(int i=0;i<n;i++) {
        cout << ans[i][1] - ans[i][0] + 1 << (i==n-1?'\n':' ');
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 8020
final_rank: 2

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n,m;cin >> n >> m;
  vi x(m),y(m);
  rep(i,0,m)cin >> x[i] >> y[i],y[i]--;
  vi idx(m);iota(ALL(idx),0);
  sort(ALL(idx),[&](int i,int j){return x[i] < x[j];});
  vector<pii> res(n);
  rep(i,0,n)res[i] = {i,i+1};
  rep(i,0,m){
    int Y = y[idx[i]];
    res[Y] = {res[Y].first,res[Y+1].second};
    res[Y+1] = res[Y];
  }
  rep(i,0,n)cout << res[i].second-res[i].first << " \n"[i+1 == n];
  

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 6884
final_rank: 6

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n,m;cin >> n >> m;
  vvi cor(n);
  vi x(m),y(m);
  rep(i,0,m){
    cin >> x[i] >> y[i];
    y[i]--;
    cor[y[i]].emplace_back(x[i]);
    cor[y[i]].emplace_back(x[i]+1);
    cor[y[i]+1].emplace_back(x[i]);
    cor[y[i]+1].emplace_back(x[i]+1);
  }
  rep(i,0,n){
    cor[i].emplace_back(0);
    cor[i].emplace_back(MOD);
    sort(ALL(cor[i]));cor[i].erase(unique(ALL(cor[i])),cor[i].end());
  }
  vi rui(n+1);
  rep(i,0,n)rui[i+1] = rui[i] + sz(cor[i]);
  vvi v(rui[n]);
  vi in(rui[n]);
  rep(i,0,m){
    {
      int k = rui[y[i]] + LB(cor[y[i]],x[i]);
      int l = rui[y[i]+1] + LB(cor[y[i]+1],x[i]+1);
      v[k].emplace_back(l);
      in[l]++;
    }
    {
      int k = rui[y[i]] + LB(cor[y[i]],x[i]+1);
      int l = rui[y[i]+1] + LB(cor[y[i]+1],x[i]);
      v[l].emplace_back(k);
      in[k]++;
    }
  }
  rep(i,0,n)rep(j,0,sz(cor[i])-1){
    v[rui[i] + j].emplace_back(rui[i] + j+1);
    in[rui[i] + j+1]++;
  }
  vi d(rui[n]);
  queue<int> que;
  rep(i,0,n)d[rui[i]] = 1;
  rep(i,0,rui[n]){
    if(in[i] == 0){
      que.push(i);
      assert(d[i] == 1);
    }else assert(d[i] == 0);
  }
  while(sz(que)){
    int ov = que.front();que.pop();
    for(auto nv : v[ov]){
      d[nv] += d[ov];
      in[nv]--;
      if(!in[nv])que.push(nv);
    }
  }
  rep(i,0,n)cout << d[rui[i+1]-1] << " \n"[i+1 == n];
  // cout << "|||||||||" << endl;
  // rep(i,0,n){
    // cout << i << " ::::::" << endl;
    // rep(j,0,sz(cor[i]))cout << cor[i][j] << "  " << d[rui[i] + j] << endl;
  // }
  

  return 0;
}
accuracy: 0.16666666666666666
time_ms: 10
memory_kb: 20540
final_rank: 20

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


class UnionFind{
  public:
  vector<int> par;
  UnionFind(long long size) : par(size,-1){}
  bool unite(int x,int y){
    x = root(x),y = root(y);
    if(x == y)return false;
    if(par[y] < par[x])swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool find(int x,int y){
    return root(x) == root(y);
  }
  int root(int x){
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  int size(int x){
    return -par[root(x)];
  }
};


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n,m;cin >> n >> m;
  UnionFind uf(n);
  vi x(m),y(m);
  rep(i,0,m)cin >> x[i] >> y[i],y[i]--;
  vi idx(m);iota(ALL(idx),0);
  sort(ALL(idx),[&](int i,int j){return x[i] < x[j];});
  vi res(n,1);
  rep(i,0,m){
    int Y = y[idx[i]];
    uf.unite(Y,Y+1);
    chmax(res[Y],1ll*uf.size(Y));
    chmax(res[Y+1],1ll*uf.size(Y+1));
  }
  cout << res << endl;
  

  return 0;
}
accuracy: 0.19444444444444445
time_ms: 20
memory_kb: 6676
final_rank: 15

code_snippet: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m;
int main() {
	cin >> n >> m;
	vector<int> x(m), y(m); vector<pair<int, int> > st(m);
	for (int i = 0; i < m; i++) cin >> x[i] >> y[i], y[i]--, st[i] = make_pair(x[i], y[i]);
	sort(st.begin(), st.end());
	for (int i = 0; i < m; i++) x[i] = st[i].first, y[i] = st[i].second;
	vector<vector<int> > ps(n - 1);
	for (int i = 0; i < m; i++) ps[y[i]].push_back(i);
	vector<int> pl(m, -1), pr(m, -1);
	for (int i = 0; i < m; i++) {
		if (y[i] >= 1) {
			int ptr = lower_bound(ps[y[i] - 1].begin(), ps[y[i] - 1].end(), i) - ps[y[i] - 1].begin() - 1;
			if (ptr >= 0) pl[i] = ps[y[i] - 1][ptr];
		}
		if (y[i] <= n - 3) {
			int ptr = lower_bound(ps[y[i] + 1].begin(), ps[y[i] + 1].end(), i) - ps[y[i] + 1].begin() - 1;
			if (ptr >= 0) pr[i] = ps[y[i] + 1][ptr];
		}
	}
	vector<int> dpl(m), dpr(m);
	for (int i = 0; i < m; i++) {
		if (pl[i] != -1) dpl[i] = dpl[pl[i]] + 1;
		if (pr[i] != -1) dpr[i] = dpr[pr[i]] + 1;
	}
	for (int i = 0; i < n; i++) {
		if (i) cout << ' ';
		int ret = -1;
		if (i <= n - 2 && ps[i].size()) ret = dpl[ps[i].back()] + dpr[ps[i].back()];
		if (i >= 1 && ps[i - 1].size()) ret = max(ret, dpl[ps[i - 1].back()] + dpr[ps[i - 1].back()]);
		cout << ret + 2;
	}
	cout << endl;
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 13272
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n, m;
    std::cin >> n >> m;
    std::vector<std::pair<int, int>> mps(m, {0, 0});
    for (int i = 0; i < m; ++i){
        std::cin >> mps[i].first >> mps[i].second; 
    }    
    std::sort(mps.begin(), mps.end());

    std::vector<std::pair<int, int>> u_d_bounds(n + 1, {0, 0});
    for (int i = 1; i <= n; ++i){
        u_d_bounds[i].first = u_d_bounds[i].second = i;
    }

    for (int i = 0; i < m; ++i){
        u_d_bounds[mps[i].second].second = std::max(u_d_bounds[mps[i].second + 1].second, mps[i].second + 1);
        u_d_bounds[mps[i].second + 1].first = std::min(u_d_bounds[mps[i].second].first, mps[i].second);
    }

    for (int i = 1; i <= n; ++i){
        std::cout << (u_d_bounds[i].second - u_d_bounds[i].first + 1);
        if (i < n) std::cout << " ";
    }
std::cout << std::endl;
}
accuracy: 1
time_ms: 20
memory_kb: 5432
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <queue>
int N, M, X[100010], Y[100010];
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cin >> N >> M;
    using qt = std::pair<int, int>;
    std::priority_queue<qt, std::vector<qt>, std::greater<qt>> que;
    for (int i = 0 ; i < M ; i++) {
        std::cin >> X[i] >> Y[i];
        Y[i]--;
        que.push({X[i], Y[i]});
    }
    std::vector<std::pair<int, int>> cur(N);
    for (int i = 0 ; i < N ; i++) cur[i] = {i, i};
    while (que.size()) {
        const int y = que.top().second;
        que.pop();
        const auto [l1, r1] = cur[y];
        const auto [l2, r2] = cur[y + 1];
        std::pair<int, int> next{std::min(l1, l2), std::max(r1, r2)};
        cur[y] = cur[y + 1] = next;
    }
    for (int i = 0 ; i < N ; i++) std::cout << cur[i].second - cur[i].first + 1 << (i + 1 == N ? '\n' : ' ');
}
accuracy: 1
time_ms: 10
memory_kb: 6640
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

int main() {
    int N, K;
    cin >> N >> K;
    vector<pair<int,int>> P(K);
    rep(i,0,K) cin >> P[i].first >> P[i].second, P[i].second--;
    sort(ALL(P));
    vector<int> A(N), B(N);
    iota(ALL(A),0), iota(ALL(B),0);
    rep(i,0,K) {
        int C = min(A[P[i].second],A[P[i].second+1]);
        int D = max(B[P[i].second],B[P[i].second+1]);
        A[P[i].second] = A[P[i].second+1] = C;
        B[P[i].second] = B[P[i].second+1] = D;
    }
    rep(i,0,N) cout << B[i]-A[i]+1 << (i==N-1?'\n':' ');
}
accuracy: 1
time_ms: 40
memory_kb: 5480
final_rank: 10

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using ll = long long;
const int MOD = 1000000007;
const int Mod = 998244353;
const int MAX = 1000000005;
const long long INF = 1000000000000000005LL;
using namespace std;
//using namespace atcoder;

using i_i = pair<int, int>;

int main() {
    ios::sync_with_stdio(0); cin.tie();
    int n, m;
    cin >> n >> m;
    vector<int> x(m), y(m);
    for (int i = 0; i < m; i++) cin >> x[i] >> y[i];
    vector<vector<int>> arms(n-1);
    for (int i = 0; i < m; i++) {
        arms[y[i] - 1].push_back(x[i]);
    }
    vector<vector<i_i>> lower(n), upper(n);
    for (int i = 0; i < n-1; i++) {
        sort(arms[i].begin(), arms[i].end());
        lower[i+1].assign((int)arms[i].size() + 1, {0, 1});
        upper[n-1-i].assign((int)arms[i].size() + 1, {0, 1});
        for (int j = 0; j < (int)arms[i].size(); j++) {
            lower[i+1][j+1] = {arms[i][j], 0};
            upper[n-1-i][j+1] = {arms[i][j], 0};
        }
    }
    lower[0].push_back({0, 1}); upper[0].push_back({0, 1});
    vector<int> ans(n, 1);
    for (int i = 0; i < n-1; i++) {
        for (auto& [pos, cnt] : lower[i]) {
            auto itr = lower_bound(lower[i+1].begin(), lower[i+1].end(), make_pair(pos == 0 ? 1 : pos, 0));
            if (itr != lower[i+1].end()) itr->second += cnt;
        }
        for (auto& [pos, cnt] : lower[i+1]) {
            //cout << i << " " << pos << " " << cnt << endl;
            if (pos != 0) ans[i+1] += cnt;
        }

        for (auto& [pos, cnt] : upper[i]) {
            auto itr = lower_bound(upper[i+1].begin(), upper[i+1].end(), make_pair(pos == 0 ? 1 : pos, 0));
            if (itr != upper[i+1].end()) itr->second += cnt;
        }
        for (auto& [pos, cnt] : upper[i+1]) {
            if (pos != 0) ans[n-2-i] += cnt;
        }
    }
    for (int i = 0; i < n; i++) cout << ans[i] << (i+1==n ? "\n" : " ");
}
accuracy: 1
time_ms: 40
memory_kb: 33716
final_rank: 14

code_snippet: #include <bits/stdc++.h>

#define rep(i,s,n) for(int i = int(s); i < int(n); i++)
#define rrep(i,s,n) for(int i = int(n) - 1; i >= int(s); i--)
#define all(v) (v).begin(), (v).end()

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<class T>
bool chmin(T &a, T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

template<class T>
bool chmax(T &a, T b) {
    if(a >= b) return false;
    a = b;
    return true;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,m;
    std::cin >> n >> m;
    std::vector<std::pair<int,int>> xy(m);
    for(auto &[x, y]: xy) {
        std::cin >> x >> y;
        y--;
    }
    const int INF = 10000000;
    std::sort(all(xy));
    std::vector<int> ls(n), rs(n);
    {
        std::vector<int> table(n);
        std::iota(all(table), 0);
        for(auto [x, y]: xy) {
            chmin(table[y+1], table[y]);
            table[y] = INF;
        }
        rep(i,0,n) {
            if(table[i] == INF) continue;
            rep(j,table[i], i+1) {
                rs[j] = i+1;
            }
        }
    }
    {
        std::vector<int> table(n);
        std::iota(all(table), 0);
        for(auto [x, y]: xy) {
            chmax(table[y], table[y + 1]);
            table[y+1] = -INF;
        }
        rrep(i,0,n) {
            if(table[i] == -INF) continue;
            rep(j,i, table[i] + 1) {
                ls[j] = i;
            }
        }
    }
    std::vector<int> imos(n+1, 0);
    rep(i,0,n) {
        int l = ls[i], r = rs[i];
        // std::cerr << l << " " << r << '\n';
        imos[l]++;
        imos[r]--;
    }
    rep(i,0,n) imos[i+1] += imos[i];
    rep(i,0,n) {
        std::cout << imos[i] << " \n"[i == n-1];
    }
}
accuracy: 1
time_ms: 20
memory_kb: 6332
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define ALL(v) v.begin(),v.end()

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> lr(n), xy(m);
  for (int i = 0; i < n; ++i) lr[i] = {i, i + 1};
  for (int i = 0; i < m; ++i)
  {
    int x, y;
    cin >> x >> y;
    xy[i] = {x, y};
  }
  sort(ALL(xy));
  for (int i = 0; i < m; ++i)
  {
    int idx = xy[i].second - 1;
    auto tmp = make_pair(min(lr[idx].first, lr[idx + 1].first), max(lr[idx].second, lr[idx + 1].second));
    lr[idx] = lr[idx + 1] = tmp;
  }
  for (int i = 0; i < n; ++i) cout << lr[i].second - lr[i].first << " \n"[i == n - 1];
}
accuracy: 1
time_ms: 40
memory_kb: 5448
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
using ll = long long;
template<class T> bool chmin(T &a,const T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a,const T b){if(a<b){a=b;return 1;}return 0;}
const int INF = (1<<30)-1;
const int mod=998244353;
using ld = long double;
const ld P=acosl(-1)/(ld)(180);
#define all(p) p.begin(),p.end()

int main(){
	int n,m;
	cin>>n>>m;
	vector<pair<int,int>> q(m);
	rep(i,0,m) cin>>q[i].first>>q[i].second;
	sort(all(q));
	vector<int> L(n);
	rep(i,0,n) L[i]=i;
	auto R=L;
	vector<int> ansl(n),ansr(n);
	for(auto x:q){
		int ind=x.second;
		if(L[ind]!=-1){
			if(L[ind-1]!=-1){
				ansl[L[ind]]=n+L[ind-1];
			}
			else{
				L[ind-1]=L[ind];
			}
			L[ind]=-1;
		}
		if(R[ind-1]!=-1){
			if(R[ind]!=-1){
				ansr[R[ind-1]]=n+R[ind];
			}else{
				R[ind]=R[ind-1];
			}
			R[ind-1]=-1;
		}
	}
	rep(i,0,n){
		if(L[i]!=-1) ansl[L[i]]=i;
		if(R[i]!=-1) ansr[R[i]]=i;
	}
	vector<int> ans(n+1);
	auto f=[&](auto self,vector<int> &p,int ind)->void{
		if(p[ind]<n) return;
		self(self,p,p[ind]-n);
		p[ind]=p[p[ind]-n];
		return;
	};
	rep(i,0,n){
		f(f,ansl,i);
		f(f,ansr,i);
		ans[ansl[i]]++;
		ans[ansr[i]+1]--;
	}
	rep(i,0,n){
		if(i) cout<<" ";
		cout<<ans[i];
		ans[i+1]+=ans[i];
	}
	cout<<"\n";
}
accuracy: 1
time_ms: 50
memory_kb: 7856
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;

bool compare(pair <int, int> l , pair <int, int> r){
    if (l.second == r.second) {
        return l.first <= r.first;
    }
    return l.second < r.second;
}

bool compare_2(pair <int, int> l , pair <int, int> r){
    if (l.second == r.second) {
        return l.first >= r.first;
    }
    return l.second < r.second;
}

int n;
int m;
int min_value[200007];
int max_value[200007];
vector <pair <int, int>> a;

pair <int, int> find_max(int i, int k, int current_v) {
    for (int j=k; j<a.size(); j++){
        if (a[j].second == i) {
            if (a[j].first > current_v) {
                pair <int, int> max_re = find_max(i + 1, j + 1, a[j].first);
                max_value[i] = max_re.first;
                return {max_value[i], max_re.second};
            }
        }
        else if (a[j].second > i){
            break;
        }
    }

    return {i, k};
}

pair <int, int> find_min(int i, int k, int current_v) {
    for (int j=k; j>=0; j--){
        if (a[j].second == i) {
            if (a[j].first > current_v) {
                pair <int, int> min_re = find_min(i - 1, j - 1, a[j].first);
                min_value[i] = min_re.first;
                return {min_value[i], min_re.second};
            }
        }
        else if (a[j].second < i){
            break;
        }
    }

    return {i, k};
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    cin >> n;
    cin >> m;

    a.resize(m);
    for (int i=0; i<m; i++){
        cin >> a[i].first >> a[i].second;
    }


    for (int i=1; i<=n; i++){
        min_value[i] = i;
        max_value[i] = i;
    }

    for (auto p : a) {
        min_value[p.second + 1] = p.second;
        max_value[p.second] = p.second + 1;
    }

    sort(a.begin(), a.end(), compare);

    pair <int, int> i = {1, 0};
    while (i.first != n + 1){
        pair <int, int> k = find_max(i.first, i.second, 0);
        if (i.first == k.first) {
            i = k;
            i.first++;
        }
        else{
            i = k;
        }
    }

    for (int i=0; i<m; i++){
        a[i].second++;
    }

    sort(a.begin(), a.end(), compare_2);
//    sort(a.begin(), a.end(), compare_2);
    i = {n, m - 1};
    while (i.first != 0) {
        pair <int, int> k = find_min(i.first, i.second, 0);
        if (i.first == k.first) {
            i = k;
            i.first--;
        }
        else{
            i = k;
        }
    }

//    for (int i=1; i<=n; i++){
//        cout << min_value[i] << '-' << max_value[i] << '\n';
//    }

    int lanes[200007];
    for (int i=1; i<=n; i++){
        lanes[i] = 0;
    }

    for (int i=1; i<=n; i++){
        lanes[min_value[i]]++;
        if (max_value[i] != n) {
            lanes[max_value[i] + 1]--;
        }
    }

    for (int i=2; i<=n; i++){
        lanes[i] = lanes[i - 1] + lanes[i];
    }

    for (int i=1; i<n; i++){
        cout << lanes[i] << ' ';
    }

    cout << lanes[n] << '\n';

}
accuracy: 0.19444444444444445
time_ms: 50
memory_kb: 4888
final_rank: 19

code_snippet: #include <bits/stdc++.h>

using namespace std;

bool compare(pair <int, int> l , pair <int, int> r){
    if (l.second == r.second) {
        return l.first <= r.first;
    }
    return l.second < r.second;
}

bool compare_2(pair <int, int> l , pair <int, int> r){
    if (l.second == r.second) {
        return l.first >= r.first;
    }
    return l.second < r.second;
}

int n;
int m;
int min_value[200007];
int max_value[200007];
vector <pair <int, int>> a;

pair <int, int> find_max(int i, int k, int current_v) {
    for (int j=k; j<a.size(); j++){
        if (a[j].second == i) {
            if (a[j].first >= current_v) {
                pair <int, int> max_re = find_max(i + 1, j + 1, a[j].first);
                max_value[i] = max_re.first;
                return {max_value[i], max_re.second};
            }
        }
        else if (a[j].second > i){
            break;
        }
    }

    return {i, k};
}

pair <int, int> find_min(int i, int k, int current_v) {
    for (int j=k; j>=0; j--){
        if (a[j].second == i - 1) {
            if (a[j].first >= current_v) {
                pair <int, int> min_re = find_min(i - 1, j - 1, a[j].first);
                min_value[i] = min_re.first;
                return {min_value[i], min_re.second};
            }
        }
        else if (a[j].second < i - 1){
            break;
        }
    }

    return {i, k};
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    cin >> n;
    cin >> m;

    a.resize(m);
    for (int i=0; i<m; i++){
        cin >> a[i].first >> a[i].second;
    }

    sort(a.begin(), a.end(), compare);

    for (int i=1; i<=n; i++){
        min_value[i] = i;
        max_value[i] = i;
    }

    pair <int, int> i = {1, 0};
    while (i.first != n){
        pair <int, int> k = find_max(i.first, i.second, 0);
        if (i.first == k.first) {
            i = k;
            i.first++;
        }
        else{
            i = k;
        }
    }

    sort(a.begin(), a.end(), compare_2);
//    sort(a.begin(), a.end(), compare_2);
    i = {n, m - 1};
    while (i.first != 1) {
        pair <int, int> k = find_min(i.first, i.second, 0);
        if (i.first == k.first) {
            i = k;
            i.first--;
        }
        else{
            i = k;
        }
    }

//    for (int i=1; i<=n; i++){
//        cout << min_value[i] << '-' << max_value[i] << '\n';
//    }

    int lanes[200007];
    for (int i=1; i<=n; i++){
        lanes[i] = 0;
    }

    for (int i=1; i<=n; i++){
        lanes[min_value[i]]++;
        if (max_value[i] != n) {
            lanes[max_value[i] + 1]--;
        }
    }

    for (int i=2; i<=n; i++){
        lanes[i] = lanes[i - 1] + lanes[i];
    }

    for (int i=1; i<n; i++){
        cout << lanes[i] << ' ';
    }

    cout << lanes[n] << '\n';

}
accuracy: 0.19444444444444445
time_ms: 40
memory_kb: 4836
final_rank: 18

code_snippet: #include <bits/stdc++.h>

using namespace std;

bool compare(pair <int, int> l , pair <int, int> r){
    if (l.second == r.second) {
        return l.first <= r.first;
    }
    return l.second < r.second;
}

bool compare_2(pair <int, int> l , pair <int, int> r){
    if (l.second == r.second) {
        return l.first >= r.first;
    }
    return l.second > r.second;
}

int n;
int m;
int min_value[200007];
int max_value[200007];
vector <pair <int, int>> a;

pair <int, int> find_max(int i, int k, int current_v) {
    for (int j=k; j<a.size(); j++){
        if (a[j].second == i) {
            if (a[j].first >= current_v) {
                pair <int, int> max_re = find_max(i + 1, j + 1, a[j].first);
                max_value[i] = max_re.first;
                return {max_value[i], max_re.second};
            }
        }
        else if (a[j].second > i){
            break;
        }
    }

    return {i, k};
}

pair <int, int> find_min(int i, int k, int current_v) {
    for (int j=k; j>=0; j--){
        if (a[j].second == i - 1) {
            if (a[j].first >= current_v) {
                pair <int, int> min_re = find_min(i - 1, j - 1, a[j].first);
                min_value[i] = min_re.first;
                return {min_value[i], min_re.second};
            }
        }
        else if (a[j].second < i - 1){
            break;
        }
    }

    return {i, k};
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    cin >> n;
    cin >> m;

    a.resize(m);
    for (int i=0; i<m; i++){
        cin >> a[i].first >> a[i].second;
    }

    sort(a.begin(), a.end(), compare);

    for (int i=1; i<=n; i++){
        min_value[i] = i;
        max_value[i] = i;
    }

    pair <int, int> i = {1, 0};
    while (i.first != n){
        pair <int, int> k = find_max(i.first, i.second, 0);
        if (i.first == k.first) {
            i = k;
            i.first++;
        }
        else{
            i = k;
        }
    }

    i = {n, m - 1};
    while (i.first != 1) {
        pair <int, int> k = find_min(i.first, i.second, 0);
        if (i.first == k.first) {
            i = k;
            i.first--;
        }
        else{
            i = k;
        }
    }

//    for (int i=1; i<=n; i++){
//        cout << min_value[i] << '-' << max_value[i] << '\n';
//    }

    int lanes[200007];
    for (int i=1; i<=n; i++){
        lanes[i] = 0;
    }

    for (int i=1; i<=n; i++){
        lanes[min_value[i]]++;
        if (max_value[i] != n) {
            lanes[max_value[i] + 1]--;
        }
    }

    for (int i=2; i<=n; i++){
        lanes[i] = lanes[i - 1] + lanes[i];
    }

    for (int i=1; i<n; i++){
        cout << lanes[i] << ' ';
    }

    cout << lanes[n] << '\n';

}
accuracy: 0.19444444444444445
time_ms: 40
memory_kb: 4748
final_rank: 16

code_snippet: #include "bits/stdc++.h"

using namespace std;

int main(){
    int n,m;cin>>n>>m;
    vector<array<int,2>>q(m);
    for (int i = 0; i < m; ++i) {
        cin>>q[i][0]>>q[i][1];
        q[i][1]--;
    }
    vector<array<int,2>>ans(n);
    for (int i = 0; i < n; ++i) {
        ans[i]={i,i};
    }
    std::sort(q.begin(), q.end());
    for(auto [_,i]:q){
        ans[i+1][0]=min(ans[i+1][0],ans[i][0]);
        ans[i][1]=max(ans[i][1],ans[i+1][1]);
    }
    vector<int>ret(n);
    for (int i = 0; i < n; ++i) {
        cout<<ans[i][1]-ans[i][0]+1;
        if(i==n-1){
            cout<<'\n';
        }
        else{
            cout<<' ';
        }
    }
}
accuracy: 1
time_ms: 40
memory_kb: 6212
final_rank: 11

code_snippet: #include <bits/stdc++.h>

#ifdef _MSC_VER
#  include <intrin.h>
#else
#  include <x86intrin.h>
#endif

#include <limits>
#include <type_traits>

namespace suisen {
// ! utility
template <typename ...Types>
using constraints_t = std::enable_if_t<std::conjunction_v<Types...>, std::nullptr_t>;
template <bool cond_v, typename Then, typename OrElse>
constexpr decltype(auto) constexpr_if(Then&& then, OrElse&& or_else) {
    if constexpr (cond_v) {
        return std::forward<Then>(then);
    } else {
        return std::forward<OrElse>(or_else);
    }
}

// ! function
template <typename ReturnType, typename Callable, typename ...Args>
using is_same_as_invoke_result = std::is_same<std::invoke_result_t<Callable, Args...>, ReturnType>;
template <typename F, typename T>
using is_uni_op = is_same_as_invoke_result<T, F, T>;
template <typename F, typename T>
using is_bin_op = is_same_as_invoke_result<T, F, T, T>;

template <typename Comparator, typename T>
using is_comparator = std::is_same<std::invoke_result_t<Comparator, T, T>, bool>;

// ! integral
template <typename T, typename = constraints_t<std::is_integral<T>>>
constexpr int bit_num = std::numeric_limits<std::make_unsigned_t<T>>::digits;
template <typename T, unsigned int n>
struct is_nbit { static constexpr bool value = bit_num<T> == n; };
template <typename T, unsigned int n>
static constexpr bool is_nbit_v = is_nbit<T, n>::value;

// ?
template <typename T>
struct safely_multipliable {};
template <>
struct safely_multipliable<int> { using type = long long; };
template <>
struct safely_multipliable<long long> { using type = __int128_t; };
template <>
struct safely_multipliable<unsigned int> { using type = unsigned long long; };
template <>
struct safely_multipliable<unsigned long int> { using type = __uint128_t; };
template <>
struct safely_multipliable<unsigned long long> { using type = __uint128_t; };
template <>
struct safely_multipliable<float> { using type = float; };
template <>
struct safely_multipliable<double> { using type = double; };
template <>
struct safely_multipliable<long double> { using type = long double; };
template <typename T>
using safely_multipliable_t = typename safely_multipliable<T>::type;

template <typename T, typename = void>
struct rec_value_type {
    using type = T;
};
template <typename T>
struct rec_value_type<T, std::void_t<typename T::value_type>> {
    using type = typename rec_value_type<typename T::value_type>::type;
};
template <typename T>
using rec_value_type_t = typename rec_value_type<T>::type;

} // namespace suisen

// ! type aliases
using i128 = __int128_t;
using u128 = __uint128_t;

template <typename T>
using pq_greater = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <typename T, typename U>
using umap = std::unordered_map<T, U>;

// ! macros (capital: internal macro)
#define OVERLOAD2(_1,_2,name,...) name
#define OVERLOAD3(_1,_2,_3,name,...) name
#define OVERLOAD4(_1,_2,_3,_4,name,...) name

#define REP4(i,l,r,s)  for(std::remove_reference_t<std::remove_const_t<decltype(r)>>i=(l);i<(r);i+=(s))
#define REP3(i,l,r)    REP4(i,l,r,1)
#define REP2(i,n)      REP3(i,0,n)
#define REPINF3(i,l,s) for(std::remove_reference_t<std::remove_const_t<decltype(l)>>i=(l);;i+=(s))
#define REPINF2(i,l)   REPINF3(i,l,1)
#define REPINF1(i)     REPINF2(i,0)
#define RREP4(i,l,r,s) for(std::remove_reference_t<std::remove_const_t<decltype(r)>>i=(l)+fld((r)-(l)-1,s)*(s);i>=(l);i-=(s))
#define RREP3(i,l,r)   RREP4(i,l,r,1)
#define RREP2(i,n)     RREP3(i,0,n)

#define rep(...)    OVERLOAD4(__VA_ARGS__, REP4   , REP3   , REP2   )(__VA_ARGS__)
#define rrep(...)   OVERLOAD4(__VA_ARGS__, RREP4  , RREP3  , RREP2  )(__VA_ARGS__)
#define repinf(...) OVERLOAD3(__VA_ARGS__, REPINF3, REPINF2, REPINF1)(__VA_ARGS__)

#define CAT_I(a, b) a##b
#define CAT(a, b) CAT_I(a, b)
#define UNIQVAR(tag) CAT(tag, __LINE__)
#define loop(n) for (std::remove_reference_t<std::remove_const_t<decltype(n)>> UNIQVAR(loop_variable) = n; UNIQVAR(loop_variable) --> 0;)

#define all(iterable) std::begin(iterable), std::end(iterable)
#define input(type, ...) type __VA_ARGS__; read(__VA_ARGS__)

#ifdef LOCAL
#  define debug(...) debug_internal(#__VA_ARGS__, __VA_ARGS__)

template <class T, class... Args>
void debug_internal(const char* s, T&& first, Args&&... args) {
    constexpr const char* prefix = "[\033[32mDEBUG\033[m] ";
    constexpr const char* open_brakets = sizeof...(args) == 0 ? "" : "(";
    constexpr const char* close_brakets = sizeof...(args) == 0 ? "" : ")";
    std::cerr << prefix << open_brakets << s << close_brakets << ": " << open_brakets << std::forward<T>(first);
    ((std::cerr << ", " << std::forward<Args>(args)), ...);
    std::cerr << close_brakets << "\n";
}

#else
#  define debug(...) void(0)
#endif

// ! I/O utilities

// __int128_t
std::ostream& operator<<(std::ostream& dest, __int128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char* d = std::end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            --d;
            *d = '-';
        }
        int len = std::end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(std::ios_base::badbit);
        }
    }
    return dest;
}
// __uint128_t
std::ostream& operator<<(std::ostream& dest, __uint128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
        char buffer[128];
        char* d = std::end(buffer);
        do {
            --d;
            *d = "0123456789"[value % 10];
            value /= 10;
        } while (value != 0);
        int len = std::end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(std::ios_base::badbit);
        }
    }
    return dest;
}

// pair
template <typename T, typename U>
std::ostream& operator<<(std::ostream& out, const std::pair<T, U>& a) {
    return out << a.first << ' ' << a.second;
}
// tuple
template <unsigned int N = 0, typename ...Args>
std::ostream& operator<<(std::ostream& out, const std::tuple<Args...>& a) {
    if constexpr (N >= std::tuple_size_v<std::tuple<Args...>>) {
        return out;
    } else {
        out << std::get<N>(a);
        if constexpr (N + 1 < std::tuple_size_v<std::tuple<Args...>>) {
            out << ' ';
        }
        return operator<<<N + 1>(out, a);
    }
}
// vector
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& a) {
    for (auto it = a.begin(); it != a.end();) {
        out << *it;
        if (++it != a.end()) out << ' ';
    }
    return out;
}
// array
template <typename T, size_t N>
std::ostream& operator<<(std::ostream& out, const std::array<T, N>& a) {
    for (auto it = a.begin(); it != a.end();) {
        out << *it;
        if (++it != a.end()) out << ' ';
    }
    return out;
}
inline void print() { std::cout << '\n'; }
template <typename Head, typename... Tail>
inline void print(const Head& head, const Tail &...tails) {
    std::cout << head;
    if (sizeof...(tails)) std::cout << ' ';
    print(tails...);
}
template <typename Iterable>
auto print_all(const Iterable& v, std::string sep = " ", std::string end = "\n") -> decltype(std::cout << *v.begin(), void()) {
    for (auto it = v.begin(); it != v.end();) {
        std::cout << *it;
        if (++it != v.end()) std::cout << sep;
    }
    std::cout << end;
}

__int128_t parse_i128(std::string& s) {
    __int128_t ret = 0;
    for (int i = 0; i < int(s.size()); i++) if ('0' <= s[i] and s[i] <= '9') ret = 10 * ret + s[i] - '0';
    if (s[0] == '-') ret = -ret;
    return ret;
}
__uint128_t parse_u128(std::string& s) {
    __uint128_t ret = 0;
    for (int i = 0; i < int(s.size()); i++) if ('0' <= s[i] and s[i] <= '9') ret = 10 * ret + s[i] - '0';
    return ret;
}
// __int128_t
std::istream& operator>>(std::istream& in, __int128_t& v) {
    std::string s;
    in >> s;
    v = parse_i128(s);
    return in;
}
// __uint128_t
std::istream& operator>>(std::istream& in, __uint128_t& v) {
    std::string s;
    in >> s;
    v = parse_u128(s);
    return in;
}
// pair
template <typename T, typename U>
std::istream& operator>>(std::istream& in, std::pair<T, U>& a) {
    return in >> a.first >> a.second;
}
// tuple
template <unsigned int N = 0, typename ...Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...>& a) {
    if constexpr (N >= std::tuple_size_v<std::tuple<Args...>>) {
        return in;
    } else {
        return operator>><N + 1>(in >> std::get<N>(a), a);
    }
}
// vector
template <typename T>
std::istream& operator>>(std::istream& in, std::vector<T>& a) {
    for (auto it = a.begin(); it != a.end(); ++it) in >> *it;
    return in;
}
// array
template <typename T, size_t N>
std::istream& operator>>(std::istream& in, std::array<T, N>& a) {
    for (auto it = a.begin(); it != a.end(); ++it) in >> *it;
    return in;
}
template <typename ...Args>
void read(Args &...args) {
    (std::cin >> ... >> args);
}

// ! integral utilities

// Returns pow(-1, n)
template <typename T>
constexpr inline int pow_m1(T n) {
    return -(n & 1) | 1;
}
// Returns pow(-1, n)
template <>
constexpr inline int pow_m1<bool>(bool n) {
    return -int(n) | 1;
}

// Returns floor(x / y)
template <typename T>
constexpr inline T fld(const T x, const T y) {
    return (x ^ y) >= 0 ? x / y : (x - (y + pow_m1(y >= 0))) / y;
}
template <typename T>
constexpr inline T cld(const T x, const T y) {
    return (x ^ y) <= 0 ? x / y : (x + (y + pow_m1(y >= 0))) / y;
}

template <typename T, suisen::constraints_t<suisen::is_nbit<T, 16>> = nullptr>
__attribute__((target("popcnt"))) constexpr inline int popcount(const T x) { return _mm_popcnt_u32(x); }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 32>> = nullptr>
__attribute__((target("popcnt"))) constexpr inline int popcount(const T x) { return _mm_popcnt_u32(x); }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 64>> = nullptr>
__attribute__((target("popcnt"))) constexpr inline int popcount(const T x) { return _mm_popcnt_u64(x); }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 16>> = nullptr>
constexpr inline int count_lz(const T x) { return x ? __builtin_clz(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 32>> = nullptr>
constexpr inline int count_lz(const T x) { return x ? __builtin_clz(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 64>> = nullptr>
constexpr inline int count_lz(const T x) { return x ? __builtin_clzll(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 16>> = nullptr>
constexpr inline int count_tz(const T x) { return x ? __builtin_ctz(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 32>> = nullptr>
constexpr inline int count_tz(const T x) { return x ? __builtin_ctz(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 64>> = nullptr>
constexpr inline int count_tz(const T x) { return x ? __builtin_ctzll(x) : suisen::bit_num<T>; }
template <typename T>
constexpr inline int floor_log2(const T x) { return suisen::bit_num<T> -1 - count_lz(x); }
template <typename T>
constexpr inline int ceil_log2(const T x) { return floor_log2(x) + ((x & -x) != x); }
template <typename T>
constexpr inline int kth_bit(const T x, const unsigned int k) { return (x >> k) & 1; }
template <typename T>
constexpr inline int parity(const T x) { return popcount(x) & 1; }

// ! container

template <typename T, typename Comparator, suisen::constraints_t<suisen::is_comparator<Comparator, T>> = nullptr>
auto priqueue_comp(const Comparator comparator) {
    return std::priority_queue<T, std::vector<T>, Comparator>(comparator);
}

template <typename Iterable>
auto isize(const Iterable& iterable) -> decltype(int(iterable.size())) {
    return iterable.size();
}

template <typename T, typename Gen, suisen::constraints_t<suisen::is_same_as_invoke_result<T, Gen, int>> = nullptr>
auto generate_vector(int n, Gen generator) {
    std::vector<T> v(n);
    for (int i = 0; i < n; ++i) v[i] = generator(i);
    return v;
}
template <typename T>
auto generate_range_vector(T l, T r) {
    return generate_vector(r - l, [l](int i) { return l + i; });
}
template <typename T>
auto generate_range_vector(T n) {
    return generate_range_vector(0, n);
}

template <typename T>
void sort_unique_erase(std::vector<T>& a) {
    std::sort(a.begin(), a.end());
    a.erase(std::unique(a.begin(), a.end()), a.end());
}

template <typename InputIterator, typename BiConsumer>
auto foreach_adjacent_values(InputIterator first, InputIterator last, BiConsumer f) -> decltype(f(*first++, *last), void()) {
    if (first != last) for (auto itr = first, itl = itr++; itr != last; itl = itr++) f(*itl, *itr);
}
template <typename Container, typename BiConsumer>
auto foreach_adjacent_values(Container c, BiConsumer f) -> decltype(c.begin(), c.end(), void()) {
    foreach_adjacent_values(c.begin(), c.end(), f);
}

// ! other utilities

// x <- min(x, y). returns true iff `x` has chenged.
template <typename T>
inline bool chmin(T& x, const T& y) {
    if (y >= x) return false;
    x = y;
    return true;
}
// x <- max(x, y). returns true iff `x` has chenged.
template <typename T>
inline bool chmax(T& x, const T& y) {
    if (y <= x) return false;
    x = y;
    return true;
}

template <typename T, std::enable_if_t<std::is_integral_v<T>, std::nullptr_t> = nullptr>
std::string bin(T val, int bit_num = -1) {
    std::string res;
    if (bit_num >= 0) {
        for (int bit = bit_num; bit-- > 0;) res += '0' + ((val >> bit) & 1);
    } else {
        for (; val; val >>= 1) res += '0' + (val & 1);
        std::reverse(res.begin(), res.end());
    }
    return res;
}

template <typename T, std::enable_if_t<std::is_integral_v<T>, std::nullptr_t> = nullptr>
std::vector<T> digits_low_to_high(T val, T base = 10) {
    std::vector<T> res;
    for (; val; val /= base) res.push_back(val % base);
    if (res.empty()) res.push_back(T{ 0 });
    return res;
}
template <typename T, std::enable_if_t<std::is_integral_v<T>, std::nullptr_t> = nullptr>
std::vector<T> digits_high_to_low(T val, T base = 10) {
    auto res = digits_low_to_high(val, base);
    std::reverse(res.begin(), res.end());
    return res;
}

template <typename T>
std::string join(const std::vector<T>& v, const std::string& sep, const std::string& end) {
    std::ostringstream ss;
    for (auto it = v.begin(); it != v.end();) {
        ss << *it;
        if (++it != v.end()) ss << sep;
    }
    ss << end;
    return ss.str();
}

namespace suisen {}
using namespace suisen;
using namespace std;

struct io_setup {
    io_setup(int precision = 20) {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(precision);
    }
} io_setup_ {};

// ! code from here

int main() {
    input(int, n, m);
    vector<pair<int, int>> es;
    rep(i, m) {
        input(int, x, y);
        --y;
        es.emplace_back(x, y);
    }
    sort(all(es));

    vector<pair<int, int>> ranges(n);
    rep(i, n) {
        ranges[i] = { i, i };
    }

    for (auto &[_, y] : es) {
        auto [li, ri] = ranges[y];
        auto [lj, rj] = ranges[y + 1];
        int l = min(li, lj);
        int r = max(lj, rj);
        ranges[y] = ranges[y + 1] = { l, r };
    }

    vector<int> ans;
    rep(i, n) {
        auto [l, r] = ranges[i];
        ans.push_back(r - l + 1);
    }
    print(ans);

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 6944
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,M; cin >> N >> M;
    vector<pair<int,int>> ps(M);
    rep(i,M) {
        int x,y; cin >> x >> y; y--;
        ps[i] = {x, y};
    }
    sort(ps.begin(), ps.end());

    // 隣に伝播 -> 区間になる
    vector<int> lo(N), up(N);
    rep(i,N) lo[i] = i;
    rep(i,N) up[i] = i;
    for(auto [x, y] : ps) {
        up[y] = up[y + 1];
        lo[y + 1] = lo[y];
    }

    rep(i,N) cout << up[i] - lo[i] + 1 << " \n"[i == N - 1];
}
accuracy: 1
time_ms: 20
memory_kb: 5336
final_rank: 3