Submission #440040

#TimeUsernameProblemLanguageResultExecution timeMemory
440040gromperenUntitled (POI11_tem)C++14
0 / 100
383 ms33796 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int INF = 1e9+5; struct segtree { vector<int> values; int size; void init(int n) { size = 1; while(size < n) size *= 2; values.resize(2*size); } void build(vector<int> &a, int x = 0, int lx = 0, int rx = -1) { if (rx == -1) rx = size; if (lx == rx) { if (lx < a.size()) values[x] = a[lx]; return; } int m = lx + ((rx - lx) >> 1); build(a, 2 * x, lx, m); build(a, 2 * x+1, m+1, rx); values[x] = max(values[2*x], values[2*x+1]); } int get(int l, int r, int x, int lx, int rx) { if (l <= lx && rx <= r) { return values[x]; } int m = lx + ((rx - lx) >> 1), ret = 0; if (l <= m) { ret = max(ret, get(l, r, 2*x, lx, m)); } if (m < r) { ret = max(ret, get(l, r, 2*x+1, m+1, rx)); } return ret; } int get(int l, int r) { return get(l, r, 0, 0, size); } }; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> x(n), y(n); for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; } segtree st; st.init(n); st.build(x); int ans = 0; int l = 0; int maxx = -INF; for (int i = 0; i < n; ++i) { if (y[i] < maxx) { l++; int r = i; while (l < r) { int m = l + ((r - l) >> 1); int d = st.get(m, i); if (y[i] < d) { l = m+1; } else { r = m; } } maxx = st.get(l, i); } maxx = max(maxx, x[i]); ans = max(ans, i - l + 1); } cout << ans << "\n"; return 0; }

Compilation message (stderr)

tem.cpp: In member function 'void segtree::build(std::vector<int>&, int, int, int)':
tem.cpp:19:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |    if (lx < a.size())
      |        ~~~^~~~~~~~~~
#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...