Submission #6706615


Source Code Expand

Copy
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <utility>
#define llint long long
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

struct BIT{
	int size;
	vector<int> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	int query(int i){
		int ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, int x){
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};

llint n, k;
llint x[200005], y[200005];
llint u[200005], l[200005];
llint lu[200005], rd[200005]; 
vector<llint> compX, compY;
vector<pair<P, llint> > vecX, vecY;
BIT bit(200005);

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void comp(llint x[], vector<llint> &vec)
{
	for(int i = 1; i <= n; i++) vec.push_back(x[i]);
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	for(int i = 1; i <= n; i++) x[i] = lower_bound(vec.begin(), vec.end(), x[i]) - vec.begin() + 1;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
	comp(x, compX), comp(y, compY);
	
	for(llint i = 1; i <= n; i++){
		vecX.push_back(make_pair(make_pair(x[i], y[i]), i));
		vecY.push_back(make_pair(make_pair(y[i], x[i]), i));
	}
	sort(vecX.begin(), vecX.end());
	sort(vecY.begin(), vecY.end());
	
	for(int i = 0; i < vecY.size(); i++){
		bit.add(vecY[i].first.second, 1);
		lu[vecY[i].second] = bit.query(vecY[i].first.second);
	}
	bit.init();
	for(int i = (int)vecY.size()-1; i >= 0; i--){
		bit.add(vecY[i].first.second, 1);
		rd[vecY[i].second] = bit.query(n) - bit.query(vecY[i].first.second-1);
	}
	
	/*for(int i = 1; i <= n; i++){
		cout << x[i] << " " << y[i] << " " << lu[i] << " " << rd[i] << endl;
	}*/
	
	llint ans = 0;
	for(llint i = 1; i <= n; i++){
		ans += modpow(2, n-1), ans %= mod;
		
		llint tmp = 0, cnt;
		u[i] = cnt = lower_bound(vecY.begin(), vecY.end(), make_pair(make_pair(y[i], 0LL), 0LL)) - vecY.begin();
		tmp += modpow(2, cnt), tmp %= mod;
		cnt = n - (lower_bound(vecY.begin(), vecY.end(), make_pair(make_pair(y[i]+1, 0LL), 0LL)) - vecY.begin());
		tmp += modpow(2, cnt), tmp %= mod;
		
		l[i] = cnt = lower_bound(vecX.begin(), vecX.end(), make_pair(make_pair(x[i], 0LL), 0LL)) - vecX.begin();
		tmp += modpow(2, cnt), tmp %= mod;
		cnt = n - (lower_bound(vecX.begin(), vecX.end(), make_pair(make_pair(x[i]+1, 0LL), 0LL)) - vecX.begin());
		tmp += modpow(2, cnt), tmp %= mod;
		
		lu[i] -= lower_bound(vecY.begin(), vecY.end(), make_pair(make_pair(y[i], x[i]), i)) - lower_bound(vecY.begin(), vecY.end(), make_pair(make_pair(y[i], 0LL), 0LL));
		lu[i] -= lower_bound(vecX.begin(), vecX.end(), make_pair(make_pair(x[i], y[i]), i)) - lower_bound(vecX.begin(), vecX.end(), make_pair(make_pair(x[i], 0LL), 0LL));
		lu[i] -= 1;
		tmp += mod - modpow(2, lu[i]), tmp %= mod;
		
		rd[i] -= lower_bound(vecY.begin(), vecY.end(), make_pair(make_pair(y[i]+1, 0LL), 0LL)) - lower_bound(vecY.begin(), vecY.end(), make_pair(make_pair(y[i], x[i]), i)) - 1;
		rd[i] -= lower_bound(vecX.begin(), vecX.end(), make_pair(make_pair(x[i]+1, 0LL), 0LL)) - lower_bound(vecX.begin(), vecX.end(), make_pair(make_pair(x[i], y[i]), i)) - 1;
		rd[i] -= 1;
		tmp += mod - modpow(2, rd[i]), tmp %= mod;
		
		//cout << x[i] << " " << y[i] << " " << lu[i] << " " << rd[i] << " " << u[i] << " " << l[i] << endl;
		
		cnt = u[i] - lu[i];
		cnt -= lower_bound(vecX.begin(), vecX.end(), make_pair(make_pair(x[i], y[i]), i)) - lower_bound(vecX.begin(), vecX.end(), make_pair(make_pair(x[i], 0LL), 0LL));
		tmp += mod - modpow(2, cnt), tmp %= mod;
		
		cnt = l[i] - lu[i];
		cnt -= lower_bound(vecX.begin(), vecX.end(), make_pair(make_pair(x[i], y[i]), i)) - lower_bound(vecX.begin(), vecX.end(), make_pair(make_pair(x[i], 0LL), 0LL));
		tmp += mod - modpow(2, cnt), tmp %= mod;
		
		ans += modpow(2, n-1) - tmp + mod, ans %= mod;
	}
	
	/*for(int i = 1; i <= n; i++){
		cout << x[i] << " " << y[i] << " " << u[i] << " " << l[i] << endl;
	}*/
	
	ans += mod - n, ans %= mod;
	cout << ans << endl;
	
	
	return 0;
}

Submission Info

Submission Time
Task F - Enclosed Points
User leaf1415
Language C++14 (GCC 5.4.1)
Score 600
Code Size 4431 Byte
Status AC
Exec Time 909 ms
Memory 24800 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 26
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 3 ms 7168 KB
02.txt AC 3 ms 7168 KB
03.txt AC 3 ms 7168 KB
04.txt AC 3 ms 7168 KB
05.txt AC 3 ms 7168 KB
06.txt AC 3 ms 7168 KB
07.txt AC 3 ms 7168 KB
08.txt AC 3 ms 7168 KB
09.txt AC 3 ms 7168 KB
10.txt AC 3 ms 7168 KB
11.txt AC 872 ms 23520 KB
12.txt AC 880 ms 23904 KB
13.txt AC 898 ms 24672 KB
14.txt AC 848 ms 23648 KB
15.txt AC 905 ms 23776 KB
16.txt AC 908 ms 23648 KB
17.txt AC 909 ms 24672 KB
18.txt AC 907 ms 23904 KB
19.txt AC 761 ms 24160 KB
20.txt AC 767 ms 23520 KB
21.txt AC 856 ms 24800 KB
22.txt AC 852 ms 24416 KB
23.txt AC 3 ms 7168 KB
s1.txt AC 3 ms 7168 KB
s2.txt AC 3 ms 7168 KB
s3.txt AC 3 ms 7168 KB