#line 1 "test/yukicoder/2154__imos.test.cpp" #define PROBLEM "https://yukicoder.me/problems/no/2154" #line 2 "common/template.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 2 "common/debug.hpp" #line 4 "common/debug.hpp" // --- デバッグ --- #ifndef ONLINE_JUDGE // #define printd(x) cerr << #x << ": " << x << endl; const string _TERM_ESC = "\033"; const string _TERM_BOLD = _TERM_ESC + "[1m"; const string _TERM_DECO_RESET = _TERM_ESC + "[0m"; const string _TERM_FORE_RED = _TERM_ESC + "[31m"; const string _TERM_FORE_RESET = _TERM_ESC + "[39m"; const string _TERM_BACK_RED = _TERM_ESC + "[41m"; const string _TERM_BACK_RESET = _TERM_ESC + "[49m"; #define line_debug() cerr << "line: " << __LINE__ << endl; #define coutd(x) cerr << "[debug] " << x; #define printd(x) \ cerr << _TERM_BOLD << _TERM_BACK_RED << "[debug] " << #x << " = " << x \ << _TERM_BACK_RESET << _TERM_DECO_RESET << endl; #else #define line_debug() ; #define coutd(x) ; #define printd(x) ; #endif #line 2 "common/util.hpp" #line 4 "common/util.hpp" // --- Utils --- // 二分探索 template inline T bin_search(T ok, T ng, const function is_ok) { assert(is_ok(ok) && !is_ok(ng)); assert(ok < ng); while (abs(ok - ng) > 1) { T mid = (ok + ng) / 2; if (is_ok(mid)) ok = mid; else ng = mid; } return ok; } // 合計値を求める ll sum(const vec &v) { return accumulate(all(v), 0LL); } // 可変引数min template auto min(T... a) { return min(initializer_list>{a...}); } // 可変引数max template auto max(T... a) { return max(initializer_list>{a...}); } template bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } // 3項間不等式 // 広義単調増加 bool is_increasing(int x, int y, int z) { return x <= y && y <= z; } // 半開区間[x, z)にyが含まれるか? bool is_contained(int x, int y, int z) { return x <= y && y < z; } // 頂点(x, y)が範囲に含まれるか bool is_contained(int H, int W, int x, int y) { return is_contained(0, x, H) && is_contained(0, y, W); } // rootに対し、aとbが同じ側にあるか (=は含まない) bool is_same_side(int root, int a, int b) { return (root < a) == (root < b); } // vector継承にする? template struct vec_accumulate : vec { vec data; explicit vec_accumulate(vec &v) : data(v.size()) { assert(v.size() > 0); data[0] = v[0]; for (int i = 1; i < v.size(); ++i) data[i] = data[i - 1] + v[i]; } T &operator[](int i) { assert(is_contained(-1, i, data.size())); if (i == -1) return T(); return data[i]; } }; void io_setup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << std::fixed << std::setprecision(15); } #line 2 "datastructure/imos.hpp" #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 5 "test/yukicoder/2154__imos.test.cpp" signed main() { io_setup(); 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); } imos.build(); rep(i, N) { cout << imos.get(i) << endl; } }