# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1084251 | De3b0o | Fire (BOI24_fire) | C++17 | 49 ms | 8460 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include<random>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*x)
#define rc (2*x+1)
#define sq 547
using namespace std;
ll n , m;
vector<pll> v;
ll ans;
ll l[200009] , r[200009];
ll idx;
void pro(ll s , ll e , ll t)
{
bool g = 1;
ll ans1 = t;
ll id = s;
while(id<=e)
{
while(idx<v.size())
{
if(v[idx].F<=id)
idx++;
else
break;
}
if(idx==0)
{
g=0;
break;
}
ll ne = v[idx-1].S;
if(ne<id)
{
g=0;
break;
}
ans1++;
id=ne+1;
}
if(g)
ans=min(ans,ans1);
}
int main()
{
cin >> n >> m;
ans=n+1;
for(int i = 0 ; n>i ; i++)
cin >> l[i] >> r[i];
for(int i = 0 ; n>i ; i++)
{
ll x = l[i] , y = r[i];
if(x>y)
y=m;
v.pb({x,y});
}
sort(v.begin(),v.end());
for(int i = 1 ; v.size()>i ; i++)
v[i].S=max(v[i].S,v[i-1].S);
for(int i = 0 ; n>i ; i++)
{
if(l[i]>r[i])
{
idx=0;
pro(r[i]+1,l[i]-1,1);
}
}
idx=0;
pro(0,m,0);
if(ans==n+1)
ans=-1;
cans
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |