結果
| 問題 |
No.2327 Inversion Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-31 01:00:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,788 bytes |
| コンパイル時間 | 6,106 ms |
| コンパイル使用メモリ | 236,404 KB |
| 実行使用メモリ | 6,128 KB |
| 最終ジャッジ日時 | 2024-12-28 13:27:25 |
| 合計ジャッジ時間 | 6,240 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 5 WA * 25 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:133:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
133 | auto [k, p] = v[i];
| ^
main.cpp:140:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
140 | auto [k, p] = v[i];
| ^
ソースコード
#include <algorithm>
#include <iomanip>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <numeric>
#include <vector>
#include <climits>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
const i64 INF = 1e18;
using mint = modint998244353;
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
vector<mint> fact(int x)
{
vector<mint> res(x + 1);
res[0] = 1;
rep(i, x)
{
res[i + 1] = res[i] * (i + 1);
}
return res;
}
vector<mint> finv(int x)
{
vector<mint> res(x + 1);
mint t = 1;
for(int i = 1; i <= x; i++)
{
t *= i;
}
res[x] = 1 / t;
for(int i = x; i > 0; i--)
{
res[i - 1] = res[i] * i;
}
return res;
}
auto r = fact(200005);
auto l = finv(200005);
mint comb(int x, int y)
{
if(x - y < 0 || x < 0 || y < 0) return 0;
return r[x] * l[y] * l[x - y];
}
template <int m>
std::istream &std::operator>>(std::istream &is, atcoder::static_modint<m> &a) {
long long v;
is >> v;
a = v;
return is;
}
template <int m>
std::istream &std::operator>>(std::istream &is, atcoder::dynamic_modint<m> &a) {
long long v;
is >> v;
a = v;
return is;
}
template <int m>
std::ostream &std::operator<<(std::ostream &os, const atcoder::static_modint<m> &a) { return os << a.val(); }
template <int m>
std::ostream &std::operator<<(std::ostream &os, const atcoder::dynamic_modint<m> &a) { return os << a.val(); }
mint get(i64 n) {
// 1~nの順列の転倒数の総和
if(n < 0) return 0;
if(n == 0) return 1;
return r[n] / 2 * n * (n - 1) / 2;
}
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> v;
rep(i, m) {
int p, k;
cin >> p >> k;
p--;
k--;
v.emplace_back(k, p);
}
fenwick_tree<int> fw(n), fw2(n);
sort(all(v));
// 未確定 * 未確定
mint ans = get(n - m);
// 確定 * 確定
rep(i, m) {
auto [k, p] = v[i];
ans += r[n - m] * fw.sum(p, n);
fw.add(p, 1);
}
// 確定 * 未確定
for(int i = m - 1; i >= 0; i--) {
auto [k, p] = v[i];
mint now_ans = 0;
if(n - m - 1 >= 0) now_ans += mint(n - 1 - p - fw2.sum(p, n)) * r[n - m - 1];
ans += now_ans;
fw2.add(p, 1);
}
cout << ans << endl;
return 0;
}