Submission #200251

# Submission time Handle Problem Language Result Execution time Memory
200251 2020-02-05T19:15:55 Z Diuven trapezoid (balkan11_trapezoid) C++14
100 / 100
210 ms 34284 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

const int MOD = 30013;
const int MAX = 1e5+10;
const int LG  = 18;

inline int _max(int x, int y){ return x>y ? x : y; }
inline pii add(const pii& x, const pii& y){
	pii res = {_max(x.first, y.first), 0};
	if(res.first==x.first) res.second += x.second;
	if(res.first==y.first) res.second += y.second;
	res.second %= MOD;
	return res;
}

int n;
vector<int> X, Y;
// find maximum below x (inclusive)
int find(int x, vector<int>& V){ return upper_bound(V.begin(), V.end(), x) - V.begin() - 1; }
struct tra {
	int a, b, c, d;
	void in(){
		cin>>a>>b>>c>>d;
		X.push_back(b); Y.push_back(d);
	}
} R[MAX];

struct node {
	int l, r; pii p;
} T[MAX * LG];
int rt[MAX], bck;

int make(int v, int s, int e, int y, pii pp){
	if(y<s || e<y) return v;
	T[++bck] = T[v]; v = bck;
	if(s==e){ T[v].p = pp; return v; }
	T[v].l = make(T[v].l, s, (s+e)/2, y, pp);
	T[v].r = make(T[v].r, (s+e)/2+1, e, y, pp);
	T[v].p = add(T[T[v].l].p, T[T[v].r].p);
	return v;
}
pii get(int v, int s, int e, int qr){
	if(qr<s) return {0,0};
	if(e<=qr) return T[v].p;
	return add(get(T[v].l, s, (s+e)/2, qr), get(T[v].r, (s+e)/2+1, e, qr));
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);

	cin>>n;
	for(int i=1; i<=n; i++) R[i].in();
	X.push_back(0); Y.push_back(0);
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	for(int i=1; i<=n; i++){
		R[i].a = find(R[i].a, X);
		R[i].b = find(R[i].b, X);
		R[i].c = find(R[i].c, Y);
		R[i].d = find(R[i].d, Y);
	}
	sort(R+1, R+n+1, [](tra& x, tra& y){ return x.b < y.b; });

	pii ans = {0,1};

	for(int i=1; i<=n; i++){
		int x = R[i].a, y = R[i].c;
		pii now = get(rt[x], 0, n, y);
		if(now.first==0 && now.second==0) now.second++;
		now.first++;
		ans = add(ans, now);
		if(i!=R[i].b){ puts("Wrong!"); return 42; }
		rt[i] = make(rt[i-1], 0, n, R[i].d, now);

		// cout<<R[i].a<<' '<<R[i].b<<' '<<R[i].c<<' '<<R[i].d<<": "<<ans.first<<' '<<ans.second<<'\n';
	}
	cout<<ans.first<<' '<<ans.second<<'\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 28536 KB Output is correct
2 Correct 20 ms 28536 KB Output is correct
3 Correct 20 ms 28536 KB Output is correct
4 Correct 21 ms 28536 KB Output is correct
5 Correct 22 ms 28664 KB Output is correct
6 Correct 24 ms 28664 KB Output is correct
7 Correct 26 ms 28792 KB Output is correct
8 Correct 27 ms 28844 KB Output is correct
9 Correct 34 ms 29176 KB Output is correct
10 Correct 55 ms 29740 KB Output is correct
11 Correct 59 ms 30072 KB Output is correct
12 Correct 101 ms 31476 KB Output is correct
13 Correct 127 ms 32244 KB Output is correct
14 Correct 135 ms 32624 KB Output is correct
15 Correct 154 ms 32748 KB Output is correct
16 Correct 164 ms 33132 KB Output is correct
17 Correct 168 ms 33388 KB Output is correct
18 Correct 162 ms 33644 KB Output is correct
19 Correct 161 ms 33896 KB Output is correct
20 Correct 210 ms 34284 KB Output is correct