# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
678869 | MilosMilutinovic | trapezoid (balkan11_trapezoid) | C++14 | 154 ms | 24520 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |