結果
問題 | No.1649 Manhattan Square |
ユーザー | yakki |
提出日時 | 2021-08-21 08:27:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,383 bytes |
コンパイル時間 | 1,706 ms |
コンパイル使用メモリ | 134,624 KB |
実行使用メモリ | 17,364 KB |
最終ジャッジ日時 | 2024-10-14 17:19:54 |
合計ジャッジ時間 | 17,455 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 2 ms
5,248 KB |
testcase_44 | AC | 2 ms
5,248 KB |
ソースコード
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<bitset> #include<set> #include<map> #include<stack> #include<queue> #include<deque> #include<list> #include<iomanip> #include<cmath> #include<cstring> #include<functional> #include<cstdio> #include<cstdlib> #include<numeric> #include<ctime> //#include<atcoder/all> using namespace std; //using namespace atcoder; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 //#define MOD 1000000007 #define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 #define PI acos(-1.0) const double EPS = 1e-10; using ll = long long; using Pi = pair<int,int>; using Pl = pair<ll,ll>; //using mint = modint998244353; int dh[] = {-1,1,0,0}; int dw[] = {0,0,1,-1}; template<typename T> vector<T> compress(vector<T> &v){ vector<T> res = v; sort(res.begin(),res.end()); res.erase(unique(res.begin(),res.end()),res.end()); for(auto &u : v){u = lower_bound(res.begin(),res.end(),u)-res.begin();} return res; } template<typename T> struct BinaryIndexedTree{ vector<T> bit; BinaryIndexedTree(int sz){ bit.resize(sz+1); } void add(int k, T x){ //k番目にxを加える for(int i = k; i < (int)bit.size(); i |= i+1) bit[i] += x; } T sum(int k){ //[0,k)の区間の総和を求める T res = 0; for(int i = k-1; i >= 0; i = (i&(i+1))-1){ res += bit[i]; } return res; } }; int main(){ int n; cin >> n; vector<ll> x(n),y(n); vector<Pl> xy(n); rep(i,n){ cin >> x[i] >> y[i]; xy[i].first = x[i]; xy[i].second = y[i]; } auto f = [&](auto v){ ll s1 = 0,s2 = 0,s3 = 0; rep(i,n-1){ s1 += v[i]*v[i]%MOD*(n-i-1)%MOD; s1 %= MOD; } vector<ll> sum(n+1); rep(i,n) sum[i+1] = (sum[i]+v[i]*v[i]%MOD)%MOD; rep(i,n-1){ s3 += (sum[n]-sum[i+1]+MOD)%MOD; s3 %= MOD; } vector<ll> sum2(n+1); rep(i,n) sum2[i+1] = (sum2[i]+v[i])%MOD; rep(i,n-1){ s2 += v[i]*(sum2[n]-sum2[i+1]+MOD)%MOD; s2 %= MOD; } s2 *= 2; s2 %= MOD; ll res = (s1+s3-s2+MOD)%MOD; return res; }; ll ans = f(x)+f(y); sort(xy.begin(),xy.end()); vector<ll> comp; rep(i,n) comp.push_back(xy[i].second); compress(comp); BinaryIndexedTree<ll> bit1(n),bit2(n),bit3(n),bit4(n); //1,x,y,x*yの和 ll ans2 = 0; rep(i,n){ ll l = xy[i].first; ll r = xy[i].second; ans2 += l*r%MOD*bit1.sum(comp[i]+1)%MOD; ans2 %= MOD; ans2 -= r*bit2.sum(comp[i]+1)%MOD; ans2 -= l*bit3.sum(comp[i]+1)%MOD; ans2 %= MOD; if(ans2 < 0) ans2 += MOD; ans2 += bit4.sum(comp[i]+1); ans2 %= MOD; ans2 += l*(bit3.sum(n)-bit3.sum(comp[i]+1))%MOD; ans2 %= MOD; ans2 += r*(bit2.sum(n)-bit2.sum(comp[i]+1))%MOD; ans2 %= MOD; ans2 -= l*r%MOD*(bit1.sum(n)-bit1.sum(comp[i]+1))%MOD; ans2 -= (bit4.sum(n)-bit4.sum(comp[i]+1))%MOD; ans2 %= MOD; if(ans2 < 0) ans2 += MOD; bit1.add(comp[i],1); bit2.add(comp[i],l); bit3.add(comp[i],r); bit4.add(comp[i],l*r%MOD); } ans2 *= 2; ans += ans2; ans %= MOD; cout << ans << endl; }