이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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)
{
if(id==e&&e!=m-1)
break;
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;
}
if(g&&ans1!=1)
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-1;
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);
ll mn = 1e10 , id1 = -1;
ll mx = -1 , id2 = -1;
ll mnn = 1e10;
bool ws = 0;
ll d = 0;
for(int i = 0 ; n>i ; i++)
{
if(min(l[i],r[i])==0&&max(l[i],r[i])==m-1)
ws=1;
if(l[i]==0||r[i]==m-1||l[i]>r[i])
d++;
if(l[i]>r[i])
{
if(r[i]==0)
{
mnn=min(mnn,l[i]);
}
if(l[i]<mn)
{
mn=l[i];
id1=i;
}
else if(l[i]==mn&&r[i]>r[id1])
{
mn=l[i];
id1=i;
}
if(r[i]>mx)
{
mx=r[i];
id2=i;
}
else if(r[i]==mx&&l[i]<l[id2])
{
mx=r[i];
id2=i;
}
}
}
pro(0,m-1,0);
idx=0;
if(id1!=-1)
{
idx=0;
pro(r[id1],l[id1],1);
}
if(id2!=-1)
{
idx=0;
pro(r[id2],l[id2],1);
}
idx=0;
if(mnn!=1e10)
pro(0,mnn,1);
if(ws&&d>1)
ans=2;
if(ans==n+1)
ans=-1;
cans
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void pro(long long int, long long int, long long int)':
Main.cpp:39:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | while(idx<v.size())
| ~~~^~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:78:29: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
78 | for(int i = 1 ; v.size()>i ; i++)
| ~~~~~~~~^~
# | 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... |