結果

問題 No.2197 Same Dish
ユーザー warabi0906warabi0906
提出日時 2023-02-06 09:06:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 2,157 bytes
コンパイル時間 3,912 ms
コンパイル使用メモリ 230,992 KB
実行使用メモリ 6,508 KB
最終ジャッジ日時 2023-09-17 21:04:17
合計ジャッジ時間 6,389 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,772 KB
testcase_01 AC 3 ms
4,668 KB
testcase_02 AC 3 ms
4,612 KB
testcase_03 AC 2 ms
4,652 KB
testcase_04 AC 3 ms
4,708 KB
testcase_05 AC 3 ms
4,724 KB
testcase_06 AC 3 ms
4,760 KB
testcase_07 AC 3 ms
4,664 KB
testcase_08 AC 3 ms
4,604 KB
testcase_09 AC 3 ms
4,784 KB
testcase_10 AC 3 ms
4,608 KB
testcase_11 AC 3 ms
4,620 KB
testcase_12 AC 3 ms
4,764 KB
testcase_13 AC 12 ms
4,928 KB
testcase_14 AC 63 ms
5,988 KB
testcase_15 AC 69 ms
6,184 KB
testcase_16 AC 47 ms
5,752 KB
testcase_17 AC 41 ms
5,520 KB
testcase_18 AC 71 ms
6,204 KB
testcase_19 AC 71 ms
6,508 KB
testcase_20 AC 71 ms
6,344 KB
testcase_21 AC 72 ms
6,256 KB
testcase_22 AC 69 ms
6,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include "atcoder/all"
#define debug cout << "OK" << endl;
template<typename T>
inline bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
inline bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }
inline int Code(char c) {
	if ('A' <= c and c <= 'Z')return (int)(c - 'A');
	if ('a' <= c and c <= 'z')return (int)(c - 'a');
	if ('0' <= c and c <= '9')return (int)(c - '0');
	assert(false);
}
using namespace std;
using namespace atcoder;
#define int long long
constexpr int MOD = 998244353;
constexpr int INF = (1LL << 62);
using minit = modint998244353;

template<typename T>
ostream& operator << (ostream& st, const vector<T> &v) {
	for (const T value : v) {
		st << value << " ";
	}
	return st;
}
template<typename T>
istream& operator >> (istream& st, vector<T>& v) {
	for (T &value : v) {
		st >> value;
	}
	return st;
}

//
int modpow(int a, int b, int m) {
	int res = 1;
	int q = a;
	for (int bit = 0; bit < 63; bit++) {
		if (b & (1ll << bit))res *= q;
		res %= m;
		q = q * q;
		q %= m;
	}
	return res;
}

//1-indexedですよ????????
template <typename T>
struct BIT {
	long long n;          // 配列の要素数(数列の要素数+1)
	vector<T> bit;  // データの格納先
	BIT(long long n_) : n(n_ + 1), bit(n, 0) {}

	void add(long long pos, long long c) {
		while (pos <= n) {
			bit[pos] += c;
			pos += pos & (-pos);
		}
	}


	T sum(long long pos) {
		T ans = 0;
		while (pos) {
			ans += bit[pos];
			pos -= pos & (-pos);
		}
		return ans;
	}
};
//

void solve() {
	//#1 入力
	int N, K;
	cin >> N >> K;
	vector<pair<int, int>> dat(N);
	for (int i = 0; i < N; i++) {
		cin >> dat[i].first >> dat[i].second;
	}

	//#2 sort,BITの初期化
	sort(dat.begin(), dat.end());
	BIT<int> bit(200010);

	//#3 Rの記録,ansの算出
	minit ans = 1;
	for (int i = 0; i < N; i++) {
		ans *= K - (bit.sum(200010) - bit.sum(dat[i].first));
		bit.add(dat[i].second, 1);
	}

	//#4 出力
	cout << (modpow(K, N, MOD) - ans.val() + MOD) % MOD << endl;

}
signed main() {
	int T = 1;
	// cin >> T;
	for (int i = 0; i < T; i++)
		solve();
	return 0;
}
0