#line 1 "test/yukicoder/2154__imos.test.cpp" #define PROBLEM "https://yukicoder.me/problems/no/2154" #line 2 "datastructure/imos.hpp" #line 2 "common/alias.hpp" #include // #include // #include #line 2 "common/print.hpp" #line 4 "common/print.hpp" using namespace std; // --------------- // ----- TOC ----- template ostream &operator<<(ostream &os, const pair &p); template istream &operator>>(istream &is, pair &p); template ostream &operator<<(ostream &os, const vector &v); template ostream &operator<<(ostream &os, const vector> &v); template ostream &operator<<(ostream &os, const vector>> &v); template istream &operator>>(istream &is, vector &v); template ostream &operator<<(ostream &os, const map &mp); template ostream &operator<<(ostream &os, const set &st); template ostream &operator<<(ostream &os, const multiset &st); template ostream &operator<<(ostream &os, queue q); template ostream &operator<<(ostream &os, deque q); template ostream &operator<<(ostream &os, stack st); template ostream &operator<<(ostream &os, priority_queue pq); // --- END TOC --- // --------------- template ostream &operator<<(ostream &os, const pair &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const vector &v) { os << "["; for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != (int)v.size() ? ", " : "]"); } return os; } template ostream &operator<<(ostream &os, const vector> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << endl; } return os; } template ostream &operator<<(ostream &os, const vector>> &v) { for (int i = 0; i < (int)v.size(); i++) { os << "i = " << i << endl; os << v[i]; } return os; } template istream &operator>>(istream &is, vector &v) { for (T &in : v) is >> in; return is; } template ostream &operator<<(ostream &os, const map &mp) { for (auto &[key, val] : mp) { os << key << ":" << val << " "; } return os; } template ostream &operator<<(ostream &os, const set &st) { os << "{"; auto itr = st.begin(); for (int i = 0; i < (int)st.size(); i++) { os << *itr << (i + 1 != (int)st.size() ? ", " : "}"); itr++; } return os; } template ostream &operator<<(ostream &os, const multiset &st) { auto itr = st.begin(); for (int i = 0; i < (int)st.size(); i++) { os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template ostream &operator<<(ostream &os, queue q) { while (q.size()) { os << q.front() << " "; q.pop(); } return os; } template ostream &operator<<(ostream &os, deque q) { while (q.size()) { os << q.front() << " "; q.pop_front(); } return os; } template ostream &operator<<(ostream &os, stack st) { while (st.size()) { os << st.top() << " "; st.pop(); } return os; } template ostream &operator<<(ostream &os, priority_queue pq) { while (pq.size()) { os << pq.top() << " "; pq.pop(); } return os; } #line 8 "common/alias.hpp" using namespace std; // using namespace boost::multiprecision; // --- 型エイリアス --- using ll = long long; template using vec = vector; template using vvec = vector>; template using p_queue = priority_queue; template using rp_queue = priority_queue, greater>; // --- 黒魔術 --- #define int ll // --- 制御マクロ --- #define rep(i, n) for (ll i = 0; i < n; ++i) #define all(v) begin(v), end(v) #define BIT(n) (1LL << (n)) #define MAX(type) numeric_limits::max() #define MIN(type) numeric_limits::min() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define pb push_back #define mp make_pair #define fir first #define sec second // --- 定数 --- constexpr ll INF = 1LL << 60; #line 4 "datastructure/imos.hpp" template struct imos{ private: int _n; vec _data, _raw; bool _is_build = false; public: imos(int n) : _n(n), _data(_n+1, 0), _raw(_n, 0) {} imos(vec src) : _n(src.size()), _data(_n+1, 0), _raw(_n, 0) { rep(i, _n) add(i, src[i]); } inline void add(int l, int r, T x) { assert(l < r); assert(0 <= l && r <= _n); _is_build = false; _data[l] += x; _data[r] -= x; } inline void add(int i, T x) { assert(0 <= i && i < _n); _is_build = false; add(i, i+1, x); } inline void build() { _raw[0] = _data[0]; for(int i=1; i<_n; i++) _raw[i] = _raw[i-1] + _data[i]; _is_build = true; } inline T get(int i) { assert(0 <= i && i < _n); if (!_is_build) build(); return _raw[i]; } }; #line 4 "test/yukicoder/2154__imos.test.cpp" signed main() { int N, M; cin >> N >> M; imos imos(N); rep(i, M) { int l, r; cin >> l >> r; imos.add(N-l, N-r+1, 1); } rep(i, N) { cout << imos.get(i) << endl; } }