이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000007;
ll infl=1000000000000000007;
int mod=1000000007;
int mod1=998244353;
const int N=1000007,pot=1<<21;
pair<int,int> seg[2*pot+7];
pair<int,int> get_mx(int v,int a,int b,int l,int r)
{
if(a<=l&&b>=r) return seg[v];
if(r<a||l>b) return {-inf,0};
return max(get_mx(2*v,a,b,l,(l+r)/2),get_mx(2*v+1,a,b,(l+r)/2+1,r));
}
int ins_mx(int v,int x,int i)
{
v+=pot-1;
seg[v]={x,i};
while(v>1)
{
v/=2;
seg[v]=max(seg[2*v],seg[2*v+1]);
}
}
pair<int,int> seg1[2*pot+7];
pair<int,int> get_mn(int v,int a,int b,int l,int r)
{
if(a<=l&&b>=r) return seg1[v];
if(r<a||l>b) return {inf,0};
return min(get_mn(2*v,a,b,l,(l+r)/2),get_mn(2*v+1,a,b,(l+r)/2+1,r));
}
int ins_mn(int v,int x,int i)
{
v+=pot-1;
seg1[v]={x,i};
while(v>1)
{
v/=2;
seg1[v]=min(seg1[2*v],seg1[2*v+1]);
}
}
int l[N],r[N];
int col[N];
int w[2*N];
void dfs(int v)
{
while(true)
{
pair<int,int>p=get_mx(1,l[v],r[v],1,pot);
if(p.st<=r[v]) break;
if(col[p.nd]) continue;
ins_mx(l[p.nd],-inf,p.nd);
ins_mn(r[p.nd],inf,p.nd);
col[p.nd]=3-col[v];
dfs(p.nd);
}
while(true)
{
pair<int,int>p=get_mn(1,l[v],r[v],1,pot);
if(p.st>=l[v]) break;
if(col[p.nd]) continue;
ins_mx(l[p.nd],-inf,p.nd);
ins_mn(r[p.nd],inf,p.nd);
col[p.nd]=3-col[v];
dfs(p.nd);
}
}
deque<int>Q[2];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=2*pot;i++)
{
seg[i].st=-inf;
seg1[i].st=inf;
}
for(int i=1;i<=n;i++)
{
cin>>l[i]>>r[i];
w[l[i]]=i;
w[r[i]]=-i;
ins_mx(l[i],r[i],i);
ins_mn(r[i],l[i],i);
}
int cnt=0;
for(int i=1;i<=n;i++)
{
if(col[i]) continue;
cnt++;
ins_mx(l[i],-inf,i);
ins_mn(r[i],inf,i);
col[i]=1;
dfs(i);
}
for(int i=1;i<=2*n;i++)
{
if(w[i]>0) Q[col[w[i]]-1].pb(w[i]);
else
{
w[i]=-w[i];
if(sz(Q[col[w[i]]-1])==0||Q[col[w[i]]-1].back()!=w[i])
{
cout<<0;
return 0;
}
Q[col[w[i]]-1].pop_back();
}
}
int ans=1;
for(int i=1;i<=cnt;i++) ans=ans*2%mod;
cout<<ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
port_facility.cpp: In function 'int ins_mx(int, int, int)':
port_facility.cpp:36:1: warning: no return statement in function returning non-void [-Wreturn-type]
36 | }
| ^
port_facility.cpp: In function 'int ins_mn(int, int, int)':
port_facility.cpp:55:1: warning: no return statement in function returning non-void [-Wreturn-type]
55 | }
| ^
# | 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... |