Submission #678871

#TimeUsernameProblemLanguageResultExecution timeMemory
678871MilosMilutinovictrapezoid (balkan11_trapezoid)C++14
100 / 100
174 ms21804 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...