結果

問題 No.2662 Installing Cell Towers
ユーザー ecotteaecottea
提出日時 2024-03-06 15:39:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 10,144 bytes
コンパイル時間 4,019 ms
コンパイル使用メモリ 265,980 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-06 15:39:16
合計ジャッジ時間 6,563 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 5 ms
6,676 KB
testcase_05 AC 55 ms
6,676 KB
testcase_06 AC 25 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 16 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 55 ms
6,676 KB
testcase_11 AC 48 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 23 ms
6,676 KB
testcase_14 AC 59 ms
6,676 KB
testcase_15 AC 58 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 47 ms
6,676 KB
testcase_18 AC 45 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef HIDDEN_IN_VS // 折りたたみ用

// 警告の抑制
#define _CRT_SECURE_NO_WARNINGS

// ライブラリの読み込み
#include <bits/stdc++.h>
using namespace std;

// 型名の短縮
using ll = long long; using ull = unsigned long long; // -2^63 ~ 2^63 = 9 * 10^18(int は -2^31 ~ 2^31 = 2 * 10^9)
using pii = pair<int, int>;	using pll = pair<ll, ll>;	using pil = pair<int, ll>;	using pli = pair<ll, int>;
using vi = vector<int>;		using vvi = vector<vi>;		using vvvi = vector<vvi>;	using vvvvi = vector<vvvi>;
using vl = vector<ll>;		using vvl = vector<vl>;		using vvvl = vector<vvl>;	using vvvvl = vector<vvvl>;
using vb = vector<bool>;	using vvb = vector<vb>;		using vvvb = vector<vvb>;
using vc = vector<char>;	using vvc = vector<vc>;		using vvvc = vector<vvc>;
using vd = vector<double>;	using vvd = vector<vd>;		using vvvd = vector<vvd>;
template <class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
using Graph = vvi;

// 定数の定義
const double PI = acos(-1);
const vi DX = { 1, 0, -1, 0 }; // 4 近傍(下,右,上,左)
const vi DY = { 0, 1, 0, -1 };
int INF = 1001001001; ll INFL = 4004004003104004004LL; // (int)INFL = 1010931620;

// 入出力高速化
struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } fastIOtmp;

// 汎用マクロの定義
#define all(a) (a).begin(), (a).end()
#define sz(x) ((int)(x).size())
#define lbpos(a, x) (int)distance((a).begin(), std::lower_bound(all(a), x))
#define ubpos(a, x) (int)distance((a).begin(), std::upper_bound(all(a), x))
#define Yes(b) {cout << ((b) ? "Yes\n" : "No\n");}
#define rep(i, n) for(int i = 0, i##_len = int(n); i < i##_len; ++i) // 0 から n-1 まで昇順
#define repi(i, s, t) for(int i = int(s), i##_end = int(t); i <= i##_end; ++i) // s から t まで昇順
#define repir(i, s, t) for(int i = int(s), i##_end = int(t); i >= i##_end; --i) // s から t まで降順
#define repe(v, a) for(const auto& v : (a)) // a の全要素(変更不可能)
#define repea(v, a) for(auto& v : (a)) // a の全要素(変更可能)
#define repb(set, d) for(int set = 0, set##_ub = 1 << int(d); set < set##_ub; ++set) // d ビット全探索(昇順)
#define repis(i, set) for(int i = lsb(set), bset##i = set; i >= 0; bset##i -= 1 << i, i = lsb(bset##i)) // set の全要素(昇順)
#define repp(a) sort(all(a)); for(bool a##_perm = true; a##_perm; a##_perm = next_permutation(all(a))) // a の順列全て(昇順)
#define smod(n, m) ((((n) % (m)) + (m)) % (m)) // 非負mod
#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} // 重複除去
#define EXIT(a) {cout << (a) << endl; exit(0);} // 強制終了
#define inQ(x, y, u, l, d, r) ((u) <= (x) && (l) <= (y) && (x) < (d) && (y) < (r)) // 半開矩形内判定

// 汎用関数の定義
template <class T> inline ll powi(T n, int k) { ll v = 1; rep(i, k) v *= n; return v; }
template <class T> inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // 最大値を更新(更新されたら true を返す)
template <class T> inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // 最小値を更新(更新されたら true を返す)
template <class T> inline T get(T set, int i) { return (set >> i) & T(1); }

// 演算子オーバーロード
template <class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template <class T> inline istream& operator>>(istream& is, vector<T>& v) { repea(x, v) is >> x; return is; }
template <class T> inline vector<T>& operator--(vector<T>& v) { repea(x, v) --x; return v; }
template <class T> inline vector<T>& operator++(vector<T>& v) { repea(x, v) ++x; return v; }

#endif // 折りたたみ用


#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;

#ifdef _MSC_VER
#include "localACL.hpp"
#endif

//using mint = modint1000000007;
using mint = modint998244353;
//using mint = modint; // mint::set_mod(m);

namespace atcoder {
	inline istream& operator>>(istream& is, mint& x) { ll x_; is >> x_; x = x_; return is; }
	inline ostream& operator<<(ostream& os, const mint& x) { os << x.val(); return os; }
}
using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>; using vvvvm = vector<vvvm>;
#endif


#ifdef _MSC_VER // 手元環境(Visual Studio)
#include "local.hpp"
#else // 提出用(gcc)
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(ll n) { return __builtin_popcountll(n); }
inline int lsb(int n) { return n != 0 ? __builtin_ctz(n) : -1; }
inline int lsb(ll n) { return n != 0 ? __builtin_ctzll(n) : -1; }
inline int msb(int n) { return n != 0 ? (31 - __builtin_clz(n)) : -1; }
inline int msb(ll n) { return n != 0 ? (63 - __builtin_clzll(n)) : -1; }
#define dump(...)
#define dumpel(v)
#define dump_list(v)
#define dump_mat(v)
#define input_from_file(f)
#define output_to_file(f)
#define Assert(b) { if (!(b)) while (1) cout << "OLE"; }
#endif


//【区間線型加算フェニック木】
/*
* Fenwick_tree_range_linear_add<S>(int n) : O(n)
*	v[0..n) = 0 で初期化する.
*	制約 : S の元は 2 で割れる.
*
* Fenwick_tree_range_linear_add<S>(vS v) : O(n)
*	v[0..n) で初期化する.
*
* set(int i, S b) : O(log n)
*	v[i] = b とする.
*
* S get(int i) : O(log n)
*	v[i] を返す.
*
* S sum(int l, int r) : O(log n)
*	Σv[l..r) を返す.空なら 0 を返す.
*
* add(int i, S b) : O(log n)
*	v[i] += b とする.
*
* add_const(int l, int r, S b) : O(log n)
*	v[l..r) += b とする.
*
* add_linear(int l, int r, S a, S b) : O(log n)
*	i∈[l..r) について,v[i] += a i + b とする.
*
* add_linear_right(int l, int r, S w0, S w1) : O(log n)
*	v[l..r) に昇順に等差数列 w0, w1, ... を加える.
*
* add_linear_left(int r, int l, S w0, S w1) : O(log n)
*	v(l..r] に降順に等差数列 w0, w1, ... を加える.
*/
template <class S>
class Fenwick_tree_range_linear_add {
	// ノードの個数(要素数 + 1)
	int n;

	// Σv[1..i] を acc0[i] + i acc1[i] + i^2 acc2[i] と分解する.
	// さらに accD[i] = (1/2)ΣrawD[1..i] と表されるような rawD を導入する.
	// v[D][i] : ΣrawD[*..i] の値(i:1-indexed,v[D][0] は使わない)
	vector<vector<S>> v;

	// Σv[1..r] を返す.空なら 0 を返す.(r : 1-indexed)
	S sum_sub(int r) const {
		return sum_sub(r, 0) + sum_sub(r, 1) * r + sum_sub(r, 2) * r * r;
	}

	// Σv[d][1..r] を返す.空なら 0 を返す.(r : 1-indexed)
	S sum_sub(int r, int d) const {
		S res = 0;

		// 子に向かって累積和をとっていく.
		while (r > 0) {
			res += v[d][r];

			// r の最下位ビットから 1 を減算することで次の位置を得る.
			r -= r & -r;
		}

		return res;
	}

	// v[d][i] += x とする.(i : 0-indexed)
	void add_sub(int i, S x, int d) {
		// 1-indexed に直す.
		i++;

		// 根に向かって値を加算していく.
		while (i < n) {
			v[d][i] += x;

			// i の最下位ビットに 1 を加算することで次の位置を得る.
			i += i & -i;
		}
	}

public:
	// v[0..n) = 0 で初期化する.
	Fenwick_tree_range_linear_add(int n_) : n(n_ + 1), v(3, vector<S>(n)) {}

	// v[0..n) で初期化する.
	Fenwick_tree_range_linear_add(const vector<S>& v_) : n(sz(v_) + 1), v(3, vector<S>(n)) {
		// 配列の値を仮登録する.
		rep(i, n - 1) v[0][i + 1] = 2 * v_[i];

		// 正しい値になるよう根に向かって累積和をとっていく.
		for (int pow2 = 1; 2 * pow2 < n; pow2 *= 2) {
			for (int i = 2 * pow2; i < n; i += 2 * pow2) {
				v[0][i] += v[0][i - pow2];
			}
		}
	}
	Fenwick_tree_range_linear_add() : n(0) {}

	// v[i] = b とする.(i : 0-indexed)
	void set(int i, S b) {
		add(i, b - get(i));
	}

	// v[i] を返す.(i : 0-indexed)
	S get(int i) const {
		return sum(i, i + 1);
	}

	// Σv[l..r) を返す.空なら 0 を返す.(l, r : 0-indexed)
	S sum(int l, int r) const {
		chmax(l, 0); chmin(r, n);
		if (l >= r) return 0;

		// 0-indexed での半開区間 [l, r) は,
		// 1-indexed での閉区間 [l + 1, r] に対応する.
		// よって閉区間 [1, r] の総和から閉区間 [1, l] の総和を引けば良い.
		return (sum_sub(r) - sum_sub(l)) / 2;
	}

	// v[i] += b とする.(i : 0-indexed)
	void add(int i, S b) {
		if (i < 0 || n <= i) return;

		add_sub(i, 2 * b, 0);
	}

	// v[l..r) += b とする.(l, r : 0-indexed) 
	void add_const(int l, int r, S b) {
		chmax(l, 0); chmin(r, n);
		if (l >= r) return;

		add_sub(l, -2 * l * b, 0);
		add_sub(r, 2 * r * b, 0);
		add_sub(l, 2 * b, 1);
		add_sub(r, -2 * b, 1);
	}

	// i∈[l..r) について,v[i] += a i + b とする.
	void add_linear(int l, int r, S a, S b) {
		chmax(l, 0); chmin(r, n);
		if (l >= r) return;

		add_sub(l, -l * (a * (l - 1) + 2 * b), 0);
		add_sub(r, r * (a * (r - 1) + 2 * b), 0);
		add_sub(l, -a + 2 * b, 1);
		add_sub(r, a - 2 * b, 1);
		add_sub(l, a, 2);
		add_sub(r, -a, 2);
	}

	// v[l..r) に昇順に等差数列 w0, w1, ... を加える.
	void add_linear_right(int l, int r, S w0, S w1) {
		// a l + b = w0, a(l+1) + b = w1 を解いて a, b を求める.
		ll a = w1 - w0;
		ll b = w0 - a * l;
		add_linear(l, r, a, b);
	}

	// v(l..r] に降順に等差数列 w0, w1, ... を加える.
	void add_linear_left(int r, int l, S w0, S w1) {
		// a r + b = w0, a(r-1) + b = w1 を解いて a, b を求める.
		ll a = w0 - w1;
		ll b = w0 - a * r;
		add_linear(l + 1, r + 1, a, b);
	}

#ifdef _MSC_VER
	friend ostream& operator<<(ostream& os, const Fenwick_tree_range_linear_add& ft) {
		rep(i, ft.n - 1) os << ft.get(i) << " ";
		return os;
	}
#endif
};


int main() {
//	input_from_file("input.txt");
//	output_to_file("output.txt");

	int n, m;
	cin >> n >> m;
		
	Fenwick_tree_range_linear_add<ll> a(n + 1);

	rep(j, m) {
		int p; int q;
		cin >> p >> q;

		a.add_linear_right(p - q, p + 1, 0, 1);
		dump(a);
		a.add_linear_left(p + q, p, 0, 1);
	}

	repi(i, 1, n) cout << a.get(i) << " \n"[i == n];
}
0