結果

問題 No.1649 Manhattan Square
ユーザー kotatsugamekotatsugame
提出日時 2021-08-13 22:17:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 448 ms / 3,000 ms
コード長 1,042 bytes
コンパイル時間 1,279 ms
コンパイル使用メモリ 87,588 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-14 18:28:04
合計ジャッジ時間 18,433 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 6 ms
6,940 KB
testcase_03 AC 6 ms
6,940 KB
testcase_04 AC 6 ms
6,940 KB
testcase_05 AC 7 ms
6,944 KB
testcase_06 AC 6 ms
6,944 KB
testcase_07 AC 418 ms
8,832 KB
testcase_08 AC 432 ms
8,832 KB
testcase_09 AC 427 ms
8,704 KB
testcase_10 AC 442 ms
8,704 KB
testcase_11 AC 432 ms
8,704 KB
testcase_12 AC 349 ms
6,944 KB
testcase_13 AC 387 ms
7,552 KB
testcase_14 AC 367 ms
6,944 KB
testcase_15 AC 385 ms
7,168 KB
testcase_16 AC 343 ms
6,940 KB
testcase_17 AC 342 ms
6,944 KB
testcase_18 AC 336 ms
6,940 KB
testcase_19 AC 372 ms
7,168 KB
testcase_20 AC 354 ms
6,940 KB
testcase_21 AC 386 ms
7,680 KB
testcase_22 AC 429 ms
8,576 KB
testcase_23 AC 440 ms
8,832 KB
testcase_24 AC 428 ms
8,704 KB
testcase_25 AC 438 ms
8,704 KB
testcase_26 AC 426 ms
8,704 KB
testcase_27 AC 435 ms
8,704 KB
testcase_28 AC 439 ms
8,832 KB
testcase_29 AC 435 ms
8,704 KB
testcase_30 AC 437 ms
8,704 KB
testcase_31 AC 419 ms
8,704 KB
testcase_32 AC 432 ms
8,832 KB
testcase_33 AC 426 ms
8,704 KB
testcase_34 AC 427 ms
8,704 KB
testcase_35 AC 429 ms
8,704 KB
testcase_36 AC 438 ms
8,832 KB
testcase_37 AC 425 ms
8,832 KB
testcase_38 AC 448 ms
8,704 KB
testcase_39 AC 424 ms
8,832 KB
testcase_40 AC 423 ms
8,704 KB
testcase_41 AC 434 ms
8,704 KB
testcase_42 AC 313 ms
8,832 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<atcoder/modint>
#include<atcoder/fenwicktree>
using namespace std;
using mint=atcoder::modint998244353;
int N;
pair<int,int>XY[2<<17];
main()
{
	cin>>N;
	mint ans=0;
	mint sx=0,sy=0;
	for(int i=0;i<N;i++)
	{
		cin>>XY[i].first>>XY[i].second;
		mint x=XY[i].first,y=XY[i].second;
		ans+=(x*x+y*y)*(N-1);
		ans-=2*sx*x+2*sy*y;
		sx+=x;
		sy+=y;
	}
	for(int _=0;_<2;_++)
	{
		mint now=0;
		vector<int>ys(N);
		for(int i=0;i<N;i++)
		{
			ys[i]=XY[i].second=(int)1e9-XY[i].second;
		}
		sort(XY,XY+N);
		sort(ys.begin(),ys.end());
		ys.erase(unique(ys.begin(),ys.end()),ys.end());
		atcoder::fenwick_tree<mint>cnt(ys.size()),xy(ys.size()),Sx(ys.size()),Sy(ys.size());
		for(int i=0;i<N;i++)
		{
			int yi=lower_bound(ys.begin(),ys.end(),XY[i].second)-ys.begin();
			mint x=XY[i].first,y=XY[i].second;
			now+=xy.sum(0,yi)+cnt.sum(0,yi)*x*y;
			now-=Sx.sum(0,yi)*y+Sy.sum(0,yi)*x;
			xy.add(yi,x*y);
			cnt.add(yi,1);
			Sx.add(yi,x);
			Sy.add(yi,y);
		}
		ans+=2*now;
	}
	cout<<ans.val()<<endl;
}
0