Submission #334827

#TimeUsernameProblemLanguageResultExecution timeMemory
334827VROOM_VARUNtrapezoid (balkan11_trapezoid)C++14
100 / 100
352 ms47956 KiB
/* ID: varunra2 LANG: C++ TASK: trapezoids */ #include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "lib/debug.h" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define debug_arr(...) \ cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__) #pragma GCC diagnostic ignored "-Wsign-compare" //#pragma GCC diagnostic ignored "-Wunused-parameter" //#pragma GCC diagnostic ignored "-Wunused-variable" #else #define debug(...) 42 #endif #define EPS 1e-9 #define IN(A, B, C) assert(B <= A && A <= C) #define INF (int)1e9 #define MEM(a, b) memset(a, (b), sizeof(a)) #define MOD 30013 #define MOD1 1000000007 #define MP make_pair #define PB push_back #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define x first #define y second const double PI = acos(-1.0); typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef map<int, int> MPII; typedef multiset<int> MSETI; typedef set<int> SETI; typedef set<string> SETS; typedef vector<int> VI; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<string> VS; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto& a : x) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef vector<int> vi; #pragma GCC diagnostic ignored "-Wsign-compare" // util functions int n; VVI vals; MPII cmp; VI dp1; VI dp2; int siz; void compress(VI& use) { sort(all(use)); use.resize(unique(all(use)) - use.begin()); rep(i, 0, sz(use)) cmp[use[i]] = i; siz = sz(use); } void init() { vals.resize(n); dp1.resize(n); dp2.resize(n); } void upd(PII& cur, PII& nw) { if (nw.x > cur.x) cur = nw; else if (nw.x == cur.x) cur.y += nw.y; } PII comb(PII a, PII b) { if (a.x > b.x) return a; if (b.x > a.x) return b; return MP(a.x, (a.y + b.y) % MOD); } const PII bad(0, 0); struct segtree { int n; VII st; void init(int _n) { n = _n; st.assign(4 * n, bad); } PII qry(int tl, int tr, int l, int r, int node) { if (l > r) return bad; if (tl > r or tr < l) return bad; if (tl <= l and tr >= r) return st[node]; int mid = (l + r) / 2; return comb(qry(tl, tr, l, mid, 2 * node + 1), qry(tl, tr, mid + 1, r, 2 * node + 2)); } void upd(int ind, PII val, int l, int r, int node) { if (ind < l or ind > r) return; if (ind == l and ind == r) { ::upd(st[node], val); return; } int mid = (l + r) / 2; upd(ind, val, l, mid, 2 * node + 1); upd(ind, val, mid + 1, r, 2 * node + 2); st[node] = comb(st[2 * node + 1], st[2 * node + 2]); } PII qry(int l, int r) { auto ret = qry(l, r, 0, n - 1, 0); // debug(l, r, ret); return ret; } void upd(int ind, int val, int cnt) { // debug(ind, val, cnt); upd(ind, MP(val, cnt), 0, n - 1, 0); } } st; int main() { // #ifndef ONLINE_JUDGE // freopen("trapezoids.in", "r", stdin); // freopen("trapezoids.out", "w", stdout); // #endif cin.sync_with_stdio(0); cin.tie(0); cin >> n; init(); VI pnts; for (int i = 0; i < n; i++) { vals[i].resize(4); for (int j = 0; j < 4; j++) { cin >> vals[i][j]; pnts.PB(vals[i][j]); } } compress(pnts); st.init(siz); VVI sweep; for (int i = 0; i < n; i++) { int a, b, c, d; a = vals[i][0], b = vals[i][1], c = vals[i][2], d = vals[i][3]; sweep.PB({a, c, i, 0}); sweep.PB({b, d, i, 1}); } sort(all(sweep)); // trav(x, sweep) debug(x); int ret = -1, cnt = 0; trav(x, sweep) { int a = x[0]; int b = x[1]; int ind = x[2]; int type = x[3]; if (type == 0) { tie(dp1[ind], dp2[ind]) = st.qry(0, cmp[b]); dp1[ind]++; if (dp1[ind] == 1) dp2[ind] = 1; if (dp1[ind] > ret) ret = dp1[ind], cnt = 0; if (dp1[ind] == ret) cnt = (cnt + dp2[ind]) % MOD; } if (type == 1) { st.upd(cmp[b], dp1[ind], dp2[ind]); } } // debug(dp1); cout << ret << " " << cnt << '\n'; return 0; }

Compilation message (stderr)

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:176:9: warning: unused variable 'a' [-Wunused-variable]
  176 |     int a = x[0];
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...