Submission #37599

# Submission time Handle Problem Language Result Execution time Memory
37599 2017-12-26T09:42:55 Z szawinis trapezoid (balkan11_trapezoid) C++14
100 / 100
359 ms 57520 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <climits>
#include <unordered_map>
using namespace std;
const int N = 1 << 19, MOD = 30013;

struct query {
	int r, type, idx;
	bool operator<(const query& rhs) const { return type < rhs.type; }
};

struct pr {
	int first, second;
};

int n, a[N], b[N], c[N], d[N], dp[N], f[N];
vector<query> segs[N];
pr ans = {INT_MIN, 0};

pr merge(pr p1, pr p2) {
	if(p1.first > p2.first) return p1;
	else if(p2.first > p1.first) return p2;
	else return {p1.first, (p1.second + p2.second) % MOD};
}

pr t[2*N];

void update(int i, int sz, int cnt) {
	i += N;
	t[i] = merge({sz, cnt}, t[i]);
	for(i >>= 1; i >= 1; i >>= 1) t[i] = merge(t[i<<1], t[i<<1|1]);
}

pr allahu(int l, int r) { // [)
	pr res = {INT_MIN, 0};
	for(l += N, r += N; l < r; l >>= 1, r >>= 1) {
		if(l & 1) res = merge(res, t[l++]);
		if(r & 1) res = merge(res, t[--r]);
	}
	return res;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
	vector<int> cc;
	unordered_map<int, int> pos;
	for(int i = 1; i <= n; i++) {
		cc.push_back(a[i]);
		cc.push_back(b[i]);
		cc.push_back(c[i]);
		cc.push_back(d[i]);
	}
	sort(cc.begin(), cc.end());
	cc.resize(distance(cc.begin(), unique(cc.begin(), cc.end())));
	for(int i = 0; i < cc.size(); i++) pos[cc[i]] = i+1;
	for(int i = 1; i <= n; i++) {
		a[i] = pos[a[i]];
		b[i] = pos[b[i]];
		c[i] = pos[c[i]];
		d[i] = pos[d[i]];
	}
	for(int i = 1; i <= n; i++) {
		segs[a[i]].push_back({c[i], 0, i});
		segs[b[i]].push_back({d[i], 1, i});
	}
	fill(t, t+2*N, (pr) {INT_MIN, 0});
	update(0, 0, 1);
	for(int l = 1; l < N; l++) {
		sort(segs[l].begin(), segs[l].end());
		for(query qq: segs[l]) {
			if(!qq.type) {
				pr res = allahu(0, c[qq.idx]);
				dp[qq.idx] = res.first; f[qq.idx] = res.second;
				++dp[qq.idx];
				ans = merge(ans, {dp[qq.idx], f[qq.idx]});
			} else {
				update(d[qq.idx], dp[qq.idx], f[qq.idx]);
			}
		}
	}
	printf("%d %d", ans.first, ans.second);
}

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:58:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < cc.size(); i++) pos[cc[i]] = i+1;
                   ^
trapezoid.cpp:46:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
trapezoid.cpp:47:78: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
                                                                              ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 34708 KB Output is correct
2 Correct 6 ms 34708 KB Output is correct
3 Correct 3 ms 34840 KB Output is correct
4 Correct 9 ms 34844 KB Output is correct
5 Correct 9 ms 35152 KB Output is correct
6 Correct 16 ms 35392 KB Output is correct
7 Correct 9 ms 35392 KB Output is correct
8 Correct 19 ms 35724 KB Output is correct
9 Correct 33 ms 37264 KB Output is correct
10 Correct 36 ms 38204 KB Output is correct
11 Correct 63 ms 40684 KB Output is correct
12 Correct 129 ms 46764 KB Output is correct
13 Correct 183 ms 48216 KB Output is correct
14 Correct 273 ms 53560 KB Output is correct
15 Correct 209 ms 50836 KB Output is correct
16 Correct 216 ms 51496 KB Output is correct
17 Correct 296 ms 55672 KB Output is correct
18 Correct 226 ms 50044 KB Output is correct
19 Correct 286 ms 56992 KB Output is correct
20 Correct 359 ms 57520 KB Output is correct