답안 #678869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678869 2023-01-06T19:25:44 Z MilosMilutinovic 사다리꼴 (balkan11_trapezoid) C++14
100 / 100
154 ms 24520 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) {
	st[p] = st[p] + 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:132:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
trapezoid.cpp:134:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  134 |   scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14000 KB Output is correct
2 Correct 9 ms 13908 KB Output is correct
3 Correct 9 ms 14052 KB Output is correct
4 Correct 10 ms 14036 KB Output is correct
5 Correct 13 ms 14164 KB Output is correct
6 Correct 18 ms 14276 KB Output is correct
7 Correct 13 ms 14372 KB Output is correct
8 Correct 14 ms 14420 KB Output is correct
9 Correct 24 ms 15028 KB Output is correct
10 Correct 33 ms 16012 KB Output is correct
11 Correct 42 ms 16576 KB Output is correct
12 Correct 98 ms 19216 KB Output is correct
13 Correct 97 ms 20248 KB Output is correct
14 Correct 107 ms 21508 KB Output is correct
15 Correct 130 ms 21860 KB Output is correct
16 Correct 130 ms 22328 KB Output is correct
17 Correct 133 ms 22860 KB Output is correct
18 Correct 129 ms 23388 KB Output is correct
19 Correct 146 ms 23928 KB Output is correct
20 Correct 154 ms 24520 KB Output is correct