mmrz's library

This documentation is automatically generated by online-judge-tools/verification-helper


Project maintained by mm-rz Hosted on GitHub Pages — Theme by mattgraham

:heavy_check_mark: verify/aoj/dsl/5_B.test.cpp

Depends on

Code

#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_B"

#include "./../../../template/template.hpp"
#include "./../../../data_structure/segment_tree_2d.hpp"

void mmrz::solve(){
    int n;
	cin >> n;
	const int  RC = 1050;
	segment_tree_2d<int> seg(RC, RC, [](auto l, auto r){return l+r;}, 0);
	while(n--){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		seg.set(y1, x1, seg.get(y1, x1)+1);
		seg.set(y1, x2, seg.get(y1, x2)-1);
		seg.set(y2, x1, seg.get(y2, x1)-1);
		seg.set(y2, x2, seg.get(y2, x2)+1);
	}
	int ans = 0;
	for(int i = 0;i < RC;i++)for(int j = 0;j < RC;j++)ans = max(ans, seg.fold(0, 0, i+1, j+1));
	cout << ans << '\n';
}
#line 1 "verify/aoj/dsl/5_B.test.cpp"
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_B"

#line 1 "template/template.hpp"
# include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double pi = acos(-1);
template<class T>constexpr T inf() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T hinf() { return inf<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); }
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); }
template<class T> bool chmin(T& a,T b) { if(a > b){a = b; return true;} return false; }
template<class T> bool chmax(T& a,T b) { if(a < b){a = b; return true;} return false; }
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(ll n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(ll n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
ll gcd(ll a, ll b) { if (b == 0)return a; return gcd(b, a%b); };
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g*b; };
ll MOD(ll x, ll m){return (x%m+m)%m; }
ll FLOOR(ll x, ll m) {ll r = (x%m+m)%m; return (x-r)/m; }
template<class T> using dijk = priority_queue<T, vector<T>, greater<T>>;
# define all(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(all((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(all((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(all((rprpr)),(rprpr).begin(),TU<char>)
# define rep(i,upupu)         for(ll i = 0, i##_len = (upupu);(i) < (i##_len);(i)++)
# define reps(i,opopo)        for(ll i = 1, i##_len = (opopo);(i) <= (i##_len);(i)++)
# define len(x)                ((ll)(x).size())
# define bit(n)               (1LL << (n))
# define pb push_back
# define eb emplace_back
# define exists(c, e)         ((c).find(e) != (c).end())

struct INIT{
	INIT(){
		std::ios::sync_with_stdio(false);
		std::cin.tie(0);
		cout << fixed << setprecision(20);
	}
}INIT;

namespace mmrz {
	void solve();
}

int main(){
	mmrz::solve();
}
#line 2 "data_structure/segment_tree_2d.hpp"

#line 5 "data_structure/segment_tree_2d.hpp"

template<typename T>struct segment_tree_2d {
	using F = std::function<T(T, T)>;
	int id(int r, int c) const {return r*2*w+c; }

	int h, w;
	std::vector<T> node;
	F combine;
	T identify;

	segment_tree_2d(int _h, int _w, F _combine, T _identify) : combine(_combine), identify(_identify){
		h = w = 1;
		while(h < _h) h <<= 1;
		while(w < _w) w <<= 1;
		node.assign(4*h*w, identify);
	}

	segment_tree_2d(std::vector<std::vector<T>> &v, F _combine, T _identify) : combine(_combine), identify(_identify){
		h = w = 1;
		while(h < (int)v.size()) h <<= 1;
		while(w < (int)v[0].size()) w <<= 1;
		node.assign(4*h*w, identify);
		for(int i = 0;i < (int)v.size(); i++){
			for(int j = 0;j < (int)v[0].size();j++){
				node[id(i+h-1, j+w-1)] = v[i][j];
			}
		}
		for(int i = 2*h-2; i > h-2;i--){
			for(int j = w-2; j >= 0;j--){
				node[id(i, j)] = combine(node[id(i, 2*j+1)], node[id(i, 2*j+2)]);
			}
		}
		for(int i = h-2;i >= 0;i--){
			for(int j = 0;j < 2*w-1;j++){
				node[id(i, j)] = combine(node[id(2*i+1, j)], node[id(2*i+2, j)]);
			}
		}
	}

	void set(int y, int x, T val){
		y += h-1;
		x += w-1;
		node[id(y, x)] = val;

		for(int j = (x+1)/2-1;j >= 0;j = (j+1)/2-1){
			node[id(y, j)] = combine(node[id(y, 2*j+1)], node[id(y, 2*j+2)]);
		}

		for(int i = (y+1)/2-1;i >= 0;i = (i+1)/2-1){
			for(int j = x;j >= 0;j = (j+1)/2-1){
				node[id(i, j)] = combine(node[id(2*i+1, j)], node[id(2*i+2, j)]);
			}
		}
	}

	T get(int y, int x){
		return node[id(y+h-1, x+w-1)];
	}

	T fold(int li, int lj, int ri, int rj){
		return fold_h(li, lj, ri, rj);
	}

	T fold_h(int li, int lj, int ri, int rj, int k=0, int si=0, int ti=-1){
		if(ti<0)ti = h;

		if(ri <= si || ti <= li)return identify;
		if(li <= si && ti <= ri)return fold_w(lj, rj, k);
		T vs = fold_h(li, lj, ri, rj, 2*k+1, si, (si+ti)/2);
		T vt = fold_h(li, lj, ri, rj, 2*k+2, (si+ti)/2, ti);
		return combine(vs, vt);
	}

	T fold_w(int lj, int rj, int i, int k=0, int sj=0, int tj=-1){
		if(tj<0) tj = w;

		if(rj <= sj || tj <= lj)return identify;
		if(lj <= sj && tj <= rj)return node[id(i, k)];
		T vs = fold_w(lj, rj, i, 2*k+1, sj, (sj+tj)/2);
		T vt = fold_w(lj, rj, i, 2*k+2, (sj+tj)/2, tj);
		return combine(vs, vt);
	}
};

#line 5 "verify/aoj/dsl/5_B.test.cpp"

void mmrz::solve(){
    int n;
	cin >> n;
	const int  RC = 1050;
	segment_tree_2d<int> seg(RC, RC, [](auto l, auto r){return l+r;}, 0);
	while(n--){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		seg.set(y1, x1, seg.get(y1, x1)+1);
		seg.set(y1, x2, seg.get(y1, x2)-1);
		seg.set(y2, x1, seg.get(y2, x1)-1);
		seg.set(y2, x2, seg.get(y2, x2)+1);
	}
	int ans = 0;
	for(int i = 0;i < RC;i++)for(int j = 0;j < RC;j++)ans = max(ans, seg.fold(0, 0, i+1, j+1));
	cout << ans << '\n';
}
Back to top page