結果

問題 No.1649 Manhattan Square
ユーザー 👑 kmjpkmjp
提出日時 2021-08-13 23:45:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 3,000 ms
コード長 2,432 bytes
コンパイル時間 2,518 ms
コンパイル使用メモリ 208,292 KB
実行使用メモリ 53,356 KB
最終ジャッジ日時 2024-04-14 21:07:09
合計ジャッジ時間 18,698 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
44,056 KB
testcase_01 AC 14 ms
43,236 KB
testcase_02 AC 16 ms
42,840 KB
testcase_03 AC 17 ms
42,988 KB
testcase_04 AC 16 ms
42,876 KB
testcase_05 AC 17 ms
43,928 KB
testcase_06 AC 16 ms
42,576 KB
testcase_07 AC 378 ms
53,220 KB
testcase_08 AC 379 ms
53,192 KB
testcase_09 AC 380 ms
53,232 KB
testcase_10 AC 389 ms
53,228 KB
testcase_11 AC 378 ms
53,224 KB
testcase_12 AC 370 ms
50,544 KB
testcase_13 AC 353 ms
49,640 KB
testcase_14 AC 363 ms
50,664 KB
testcase_15 AC 373 ms
50,776 KB
testcase_16 AC 358 ms
49,652 KB
testcase_17 AC 369 ms
50,744 KB
testcase_18 AC 342 ms
48,648 KB
testcase_19 AC 352 ms
49,392 KB
testcase_20 AC 353 ms
49,740 KB
testcase_21 AC 359 ms
50,912 KB
testcase_22 AC 370 ms
53,228 KB
testcase_23 AC 379 ms
53,228 KB
testcase_24 AC 366 ms
53,232 KB
testcase_25 AC 376 ms
53,228 KB
testcase_26 AC 375 ms
53,320 KB
testcase_27 AC 375 ms
53,228 KB
testcase_28 AC 373 ms
53,356 KB
testcase_29 AC 378 ms
53,228 KB
testcase_30 AC 381 ms
53,084 KB
testcase_31 AC 378 ms
53,336 KB
testcase_32 AC 375 ms
53,228 KB
testcase_33 AC 382 ms
53,232 KB
testcase_34 AC 375 ms
53,260 KB
testcase_35 AC 381 ms
53,188 KB
testcase_36 AC 381 ms
53,100 KB
testcase_37 AC 375 ms
53,144 KB
testcase_38 AC 373 ms
53,316 KB
testcase_39 AC 374 ms
53,228 KB
testcase_40 AC 370 ms
53,232 KB
testcase_41 AC 375 ms
53,228 KB
testcase_42 AC 245 ms
48,984 KB
testcase_43 AC 12 ms
42,496 KB
testcase_44 AC 13 ms
44,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
ll X[202020],Y[202020];
const ll mo=998244353;
vector<ll> Xs,Ys;

template<class V, int ME> class BIT_mod {
public:
	V bit[1<<ME];
	BIT_mod(){ZERO(bit);};
	V operator()(int e) {ll s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s%mo;}
	void add(int e,V v) { e++; while(e<=1<<ME) { bit[e-1]+=v; bit[e-1] -= (bit[e-1]>=mo)?mo:0; e+=e&-e;}}
};
BIT_mod<ll,20> bit_num,bit_x,bit_y,bit_xy;

vector<int> ev[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	ll ret=0;
	ll xs=0,xs2=0,ys=0,ys2=0;
	Xs.push_back(0);
	Ys.push_back(0);
	
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		
		ret+=xs2;
		ret-=2*xs*X[i];
		ret+=i*((X[i]*X[i])%mo);
		ret+=ys2;
		ret-=2*ys*Y[i];
		ret+=i*((Y[i]*Y[i])%mo);
		ret=(ret%mo+mo)%mo;
		
		(xs+=X[i])%=mo;
		(xs2+=X[i]*X[i])%=mo;
		(ys+=Y[i])%=mo;
		(ys2+=Y[i]*Y[i])%=mo;
		Xs.push_back(X[i]);
		Ys.push_back(Y[i]);
	}
	
	sort(ALL(Xs));
	sort(ALL(Ys));
	FOR(i,N) {
		X[i]=lower_bound(ALL(Xs),X[i])-Xs.begin();
		Y[i]=lower_bound(ALL(Ys),Y[i])-Ys.begin();
		ev[X[i]].push_back(i);
	}
	FOR(x,N+1) {
		FORR(i,ev[x]) {
			ll CX=Xs[X[i]];
			ll CY=Ys[Y[i]];
			//左上
			ret-=2*(bit_xy(N+1)-bit_xy(Y[i]));
			ret-=2*CX*CY%mo*(bit_num(N+1)-bit_num(Y[i]));
			ret+=2*CX%mo*(bit_y(N+1)-bit_y(Y[i]));
			ret+=2*CY%mo*(bit_x(N+1)-bit_x(Y[i]));
			ret=(ret%mo+mo)%mo;
			//左下
			ret+=2*bit_xy(Y[i]-1);
			ret+=2*CX*CY%mo*bit_num(Y[i]-1);
			ret-=2*CX%mo*bit_y(Y[i]-1);
			ret-=2*CY%mo*bit_x(Y[i]-1);
			ret=(ret%mo+mo)%mo;
		}
		FORR(i,ev[x]) {
			bit_num.add(Y[i],1);
			bit_x.add(Y[i],Xs[X[i]]);
			bit_y.add(Y[i],Ys[Y[i]]);
			bit_xy.add(Y[i],1LL*Xs[X[i]]*Ys[Y[i]]%mo);
		}
		
	}
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0