Submission #584070

# Submission time Handle Problem Language Result Execution time Memory
584070 2022-06-26T18:41:59 Z penguinhacker trapezoid (balkan11_trapezoid) C++17
100 / 100
74 ms 9976 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=1e5, M=30013;
int n;
ar<int, 4> trap[mxN];
ar<int, 2> ord[2*mxN], e[2*mxN], dp[mxN], ft[2*mxN+1];
bool vis[mxN];

ar<int, 2> cmb(ar<int, 2> a, ar<int, 2> b) {
	return a[0]!=b[0]?a[0]>b[0]?a:b:ar<int, 2>{a[0], (a[1]+b[1])%M};
}

void upd(int i, ar<int, 2> x) {
	for (++i; i<=2*n; i+=i&-i)
		ft[i]=cmb(ft[i], x);
}

ar<int, 2> qry(int i) {
	ar<int, 2> r={};
	for (++i; i; i-=i&-i)
		r=cmb(r, ft[i]);
	return r;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> trap[i][0] >> trap[i][1] >> trap[i][2] >> trap[i][3];
		e[2*i]={trap[i][0], i};
		e[2*i+1]={trap[i][1], i};
		ord[2*i]={trap[i][2], 2*i};
		ord[2*i+1]={trap[i][3], 2*i+1};
	}
	sort(e, e+2*n);
	sort(ord, ord+2*n);
	for (int i=0; i<2*n; ++i)
		trap[ord[i][1]/2][2+ord[i][1]%2]=i;
	for (int event=0; event<2*n; ++event) {
		int i=e[event][1];
		//cout << i << " " << trap[i][2] << " " << trap[i][3] << endl;
		if (!vis[i]) {
			dp[i]=qry(trap[i][2]);
			++dp[i][0];
			if (dp[i][0]==1) {
				assert(dp[i][1]==0);
				dp[i][1]=1;
			}
			vis[i]=1;
		} else {
			upd(trap[i][3], dp[i]);
		}
	}
	ar<int, 2> ans=qry(2*n);
	cout << ans[0] << " " << ans[1];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 4 ms 724 KB Output is correct
8 Correct 4 ms 724 KB Output is correct
9 Correct 7 ms 1236 KB Output is correct
10 Correct 14 ms 2248 KB Output is correct
11 Correct 20 ms 2768 KB Output is correct
12 Correct 37 ms 5196 KB Output is correct
13 Correct 44 ms 6196 KB Output is correct
14 Correct 54 ms 7248 KB Output is correct
15 Correct 57 ms 7636 KB Output is correct
16 Correct 66 ms 8028 KB Output is correct
17 Correct 71 ms 8668 KB Output is correct
18 Correct 64 ms 9136 KB Output is correct
19 Correct 69 ms 9400 KB Output is correct
20 Correct 74 ms 9976 KB Output is correct