Submission #382071

#TimeUsernameProblemLanguageResultExecution timeMemory
382071vishesh312Untitled (POI11_tem)C++17
50 / 100
1101 ms16364 KiB
#include "bits/stdc++.h" #pragma GCC optimize("unroll-loops", "Ofast") using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; */ #define all(x) begin(x), end(x) #define sz(x) (int)x.size() using ll = long long; const int mod = 1e9+7; const int mxN = 1e6; int mn[mxN], mx[mxN]; struct SegTree { int n; int t[mxN * 4]; void build(int v, int tl, int tr) { if (tl == tr) { t[v] = mn[tl]; } else { int tm = (tl + tr) / 2; build(v*2, tl, tm); build(v*2+1, tm+1, tr); t[v] = max(t[v*2], t[v*2+1]); } } int query(int v, int tl, int tr, int l, int r) { if (l > r) return -1e9; if (l == tl and r == tr) return t[v]; int tm = (tl + tr) / 2; return max(query(v*2, tl, tm, l, min(r, tm)), query(v*2+1, tm+1, tr, max(l, tm+1), r)); } SegTree(int _n) { n = _n; build(1, 0, n-1); } int query(int l, int r) { return query(1, 0, n-1, l, r); } }; void solve(int tc) { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> mn[i] >> mx[i]; } SegTree seg(n); int lo = 0, hi = n-1; int m = -1e9; int ans = 0; for (int i = 0; i < n; ++i) { if (mx[i] < m) { ++lo; hi = i; while (lo < hi) { int mid = (lo + hi) / 2; int q = seg.query(mid, i); if (mx[i] < q) lo = mid+1; else hi = mid; } m = seg.query(lo, i); } m = max(m, mn[i]); ans = max(ans, i - lo + 1); } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; for (int i = 1; i <= tc; ++i) solve(i); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...