Submission #678871

# Submission time Handle Problem Language Result Execution time Memory
678871 2023-01-06T19:26:24 Z MilosMilutinovic trapezoid (balkan11_trapezoid) C++14
100 / 100
174 ms 21804 KB
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);}
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const int N = 100100;
int n;
int a[N];
int b[N];
int c[N];
int d[N];
vector<int> ev[2 * N];

void compress(int* v, int* u) {
	vector<int> xs;
	for (int i = 0; i < n; i++) {
		xs.push_back(v[i]);
		xs.push_back(u[i]);
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for (int i = 0; i < n; i++) {
		v[i] = lower_bound(xs.begin(), xs.end(), v[i]) - xs.begin();
		u[i] = lower_bound(xs.begin(), xs.end(), u[i]) - xs.begin();
	}
}

const int MOD = 30013;
int add(int a, int b) {
	return a + b < MOD ? a + b : a + b - MOD;
}

struct Node {
	int sz, ways;

	Node() : sz(-1), ways(0) {}
	Node(int _sz, int _ways) : sz(_sz), ways(_ways) {}
};
Node const operator + (Node x, Node y) {
	Node w;
	w.sz = max(x.sz, y.sz);
	w.ways = 0;
	if (x.sz == w.sz) w.ways = add(w.ways, x.ways);
	if (y.sz == w.sz) w.ways = add(w.ways, y.ways);
	return w;
}
const int K = (1 << 20);
Node st[K];
Node dp[N];

void buildDP(int p, int l, int r) {
	st[p] = Node(0, 0);
	if (l == r) return;
	int mid = l + (r - l) / 2;
	buildDP(p * 2, l, mid);
	buildDP(p * 2 + 1, mid + 1, r);
}
Node getDP(int p, int l, int r, int tl, int tr) {
	if (l > r || l > tr || r < tl) return Node(-1, 0);
	if (tl <= l && r <= tr) return st[p];
	int mid = l + (r - l) / 2;
	return getDP(p * 2, l, mid, tl, tr) + getDP(p * 2 + 1, mid + 1, r, tl, tr);
}
void updateDP(int p, int l, int r, int i, Node nd) {
	if (l == r) {
		st[p] = st[p] + nd;
		return;
	}
	int mid = l + (r - l) / 2;
	if (i <= mid)
		updateDP(p * 2, l, mid, i, nd);
	else
		updateDP(p * 2 + 1, mid + 1, r, i, nd);
	st[p] = st[p * 2] + st[p * 2 + 1];
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
	compress(a, b);
	compress(c, d);
	for (int i = 0; i < n; i++) {
		ev[a[i]].push_back(~i);
		ev[b[i]].push_back(i);
	}
	buildDP(1, -1, 2 * N);
	for (int i = 0; i < 2 * N; i++) {
		sort(ev[i].begin(), ev[i].end());
		for (int p : ev[i]) {
			if (p < 0) {
				p = (~p);
				dp[p] = getDP(1, -1, 2 * N, -1, c[p] - 1);
				dp[p].sz += 1;
				if (dp[p].sz == 1) dp[p].ways = 1;
			} else {
				updateDP(1, -1, 2 * N, d[p], dp[p]);
			}
		}
	}
	printf("%d %d\n", st[1].sz, st[1].ways);

	return 0;
}

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:131:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
trapezoid.cpp:133:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  133 |   scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 13908 KB Output is correct
2 Correct 8 ms 13980 KB Output is correct
3 Correct 8 ms 14036 KB Output is correct
4 Correct 9 ms 14036 KB Output is correct
5 Correct 11 ms 14176 KB Output is correct
6 Correct 13 ms 14164 KB Output is correct
7 Correct 12 ms 14268 KB Output is correct
8 Correct 14 ms 14408 KB Output is correct
9 Correct 20 ms 14772 KB Output is correct
10 Correct 34 ms 15500 KB Output is correct
11 Correct 43 ms 15860 KB Output is correct
12 Correct 115 ms 17852 KB Output is correct
13 Correct 99 ms 18592 KB Output is correct
14 Correct 115 ms 19476 KB Output is correct
15 Correct 135 ms 19864 KB Output is correct
16 Correct 144 ms 20304 KB Output is correct
17 Correct 143 ms 20652 KB Output is correct
18 Correct 137 ms 20984 KB Output is correct
19 Correct 151 ms 21456 KB Output is correct
20 Correct 174 ms 21804 KB Output is correct