Submission #37595

# Submission time Handle Problem Language Result Execution time Memory
37595 2017-12-26T08:58:39 Z szawinis trapezoid (balkan11_trapezoid) C++14
88 / 100
296 ms 65444 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, swp, idx;
};

struct pr {
	int first, second;
};

int n, a[N], b[N], c[N], d[N], dp[N], f[N];
vector<query> segs[N];

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};
}

struct segtree {
	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 query(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;
	}
} t[2];

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]);

	// compress
	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++) {
		if(a[i] <= c[i]) {
			segs[a[i]].push_back({c[i], 0, 0, i});
			segs[b[i]].push_back({d[i], 1, 0, i});
		} else {
			segs[c[i]].push_back({a[i], 0, 1, i});
			segs[d[i]].push_back({b[i], 1, 1, i});
		}
	}
	fill(t[0].t, t[0].t+2*N, (pr) {INT_MIN, 0});
	fill(t[1].t, t[1].t+2*N, (pr) {INT_MIN, 0});
	t[0].update(0, 0, 0);
	t[1].update(0, 0, 0);
	for(int l = 1; l < N; l++) {
		for(query qq: segs[l]) {
			if(!qq.type) {
				pr res = merge(t[qq.swp].query(0, qq.r), t[qq.swp ^ 1].query(0, l));
				dp[qq.idx] = res.first; f[qq.idx] = res.second;
				if(!dp[qq.idx]) f[qq.idx] = 1;
				++dp[qq.idx];
			} else {
				t[qq.swp].update(qq.r, dp[qq.idx], f[qq.idx]);
			}
			// cout << l << ' ' << qq.r << ' ' << qq.type << ' ' << qq.swp << ' ' << qq.idx << ' ' << dp[qq.idx] << ' ' << f[qq.idx] << endl;
		}
	}
	pr ans = merge(t[0].query(0, N), t[1].query(0, N));
	printf("%d %d", ans.first, ans.second);
}

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:60: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 9 ms 42896 KB Output is correct
2 Correct 13 ms 42896 KB Output is correct
3 Correct 16 ms 43028 KB Output is correct
4 Correct 9 ms 43032 KB Output is correct
5 Correct 16 ms 43340 KB Output is correct
6 Partially correct 13 ms 43580 KB Partially correct
7 Correct 19 ms 43580 KB Output is correct
8 Correct 13 ms 43912 KB Output is correct
9 Correct 29 ms 45452 KB Output is correct
10 Correct 53 ms 46392 KB Output is correct
11 Correct 79 ms 48740 KB Output is correct
12 Correct 199 ms 54952 KB Output is correct
13 Partially correct 163 ms 56404 KB Partially correct
14 Partially correct 279 ms 61748 KB Partially correct
15 Correct 236 ms 58628 KB Output is correct
16 Correct 259 ms 59420 KB Output is correct
17 Correct 273 ms 63728 KB Output is correct
18 Correct 206 ms 58232 KB Output is correct
19 Correct 279 ms 64916 KB Output is correct
20 Partially correct 296 ms 65444 KB Partially correct