Submission #432004

#TimeUsernameProblemLanguageResultExecution timeMemory
432004ak2006Untitled (POI11_tem)C++14
24 / 100
1089 ms41960 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>; const ll mod = 1e9 + 7,inf = 1e18; #define pb push_back #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define lc 2 * no #define rc 2 * no + 1 void setIO() { fast; } int n = 1e6 + 5; vi a(n),tree(4 * n),b(n); void build(int no,int l,int r) { if (l == r){tree[no] = a[l];return;} int mid = (l + r)/2; build(lc,l,mid),build(rc,mid + 1,r); tree[no] = max(tree[lc],tree[rc]); } int MAX(int no,int l,int r,int i,int j) { if (l > j or i > r)return -1e9; if (i <= l && r <= j)return tree[no]; int mid = (l + r)/2; return max(MAX(lc,l,mid,i,j),MAX(rc,mid + 1,r,i,j)); } int search(int i) { //binary search for the smallest j such that MAX(1,1,n,j,i) <= b[i] int l = 1,r = i,pos = i; while (l <= r){ int mid = (l + r)/2; if (MAX(1,1,n,mid,i) <= b[i]){ pos = mid; r = mid - 1; } else l = mid + 1; } return pos; } int main() { setIO(); cin>>n; for (int i = 1;i<=n;i++)cin>>a[i]>>b[i]; build(1,1,n); int cur = search(1); int ans = 1 - cur + 1; for (int i = 2;i<=n;i++){ int val = search(i); int now = max(val,cur); ans = max(ans,i - now + 1); cur = max(cur,val); } cout<<ans; 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...