結果
問題 | No.1649 Manhattan Square |
ユーザー | milanis48663220 |
提出日時 | 2023-08-13 12:15:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 267 ms / 3,000 ms |
コード長 | 3,333 bytes |
コンパイル時間 | 1,794 ms |
コンパイル使用メモリ | 138,868 KB |
実行使用メモリ | 19,924 KB |
最終ジャッジ日時 | 2024-11-21 06:55:41 |
合計ジャッジ時間 | 15,230 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 5 ms
6,816 KB |
testcase_03 | AC | 4 ms
6,816 KB |
testcase_04 | AC | 5 ms
6,816 KB |
testcase_05 | AC | 4 ms
6,816 KB |
testcase_06 | AC | 4 ms
6,820 KB |
testcase_07 | AC | 262 ms
19,772 KB |
testcase_08 | AC | 262 ms
19,728 KB |
testcase_09 | AC | 267 ms
19,876 KB |
testcase_10 | AC | 260 ms
19,724 KB |
testcase_11 | AC | 257 ms
19,796 KB |
testcase_12 | AC | 215 ms
10,600 KB |
testcase_13 | AC | 246 ms
14,516 KB |
testcase_14 | AC | 229 ms
12,644 KB |
testcase_15 | AC | 237 ms
14,252 KB |
testcase_16 | AC | 210 ms
10,476 KB |
testcase_17 | AC | 211 ms
10,596 KB |
testcase_18 | AC | 204 ms
9,580 KB |
testcase_19 | AC | 235 ms
14,096 KB |
testcase_20 | AC | 219 ms
10,576 KB |
testcase_21 | AC | 241 ms
14,452 KB |
testcase_22 | AC | 258 ms
19,712 KB |
testcase_23 | AC | 258 ms
19,924 KB |
testcase_24 | AC | 257 ms
19,700 KB |
testcase_25 | AC | 259 ms
19,800 KB |
testcase_26 | AC | 257 ms
19,772 KB |
testcase_27 | AC | 258 ms
19,696 KB |
testcase_28 | AC | 251 ms
19,772 KB |
testcase_29 | AC | 252 ms
19,776 KB |
testcase_30 | AC | 265 ms
19,872 KB |
testcase_31 | AC | 265 ms
19,852 KB |
testcase_32 | AC | 262 ms
19,700 KB |
testcase_33 | AC | 262 ms
19,872 KB |
testcase_34 | AC | 264 ms
19,848 KB |
testcase_35 | AC | 261 ms
19,852 KB |
testcase_36 | AC | 259 ms
19,708 KB |
testcase_37 | AC | 260 ms
19,824 KB |
testcase_38 | AC | 266 ms
19,768 KB |
testcase_39 | AC | 263 ms
19,736 KB |
testcase_40 | AC | 259 ms
19,772 KB |
testcase_41 | AC | 258 ms
19,800 KB |
testcase_42 | AC | 186 ms
19,844 KB |
testcase_43 | AC | 2 ms
6,820 KB |
testcase_44 | AC | 2 ms
6,820 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/modint> #include <atcoder/segtree> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } template<typename T> class Compress{ public: vector<T> data; int offset; Compress(vector<T> data_, int offset=0): offset(offset){ data = data_; sort(begin(data), end(data)); data.erase(unique(begin(data), end(data)), end(data)); }; int operator[](T x) { auto p = lower_bound(data.begin(), data.end(), x); assert(x == *p); return offset+(p-data.begin()); } T inv(int x){ return data[x-offset]; } int size(){ return data.size(); } }; using P = pair<int, int>; struct S{ mint cnt, x, y, xy; S(mint cnt, mint x, mint y, mint xy): cnt(cnt), x(x), y(y), xy(xy) {} }; S op(S x, S y){ return S(x.cnt+y.cnt, x.x+y.x, x.y+y.y, x.xy+y.xy); } S e(){ return S(mint(0), mint(0), mint(0), mint(0)); } using Seg = atcoder::segtree<S, op, e>; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector<P> vp; vector<int> xs, ys; for(int i = 0; i < n; i++){ int x, y; cin >> x >> y; vp.push_back({x, y}); xs.push_back(x); ys.push_back(y); } auto sum_diff_square = [&](vector<int> xs){ mint sum = 0, sum_square = 0; for(int x: xs){ sum += x; sum_square += mint(x)*mint(x); } mint sum_prod = (sum*sum-sum_square)/2; return sum_square*(n-1) - sum_prod*2; }; mint ans = sum_diff_square(xs)+sum_diff_square(ys); auto cp = Compress<int>(ys); Seg seg(cp.size()); sort(vp.begin(), vp.end()); for(auto [x, y]: vp){ int yi = cp[y]; mint xy = mint(x)*mint(y); S sl = seg.prod(0, yi); ans += (sl.xy + xy*sl.cnt - (sl.x*y + sl.y*x))*2; S sr = seg.prod(yi, cp.size()); ans += (sr.x*y + sr.y*x - (sr.xy + xy*sr.cnt))*2; seg.set(yi, op(S(mint(1), mint(x), mint(y), xy), seg.get(yi))); } cout << ans << endl; }