이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
typedef pair<int,int> ii;
typedef long long ll;
#define mod 1000000007
struct node{
int s,e,m,n0,n1;
node *l,*r;
node(int _s,int _e){
s=_s;e=_e;m=(s+e)/2;n0=0;n1=0;
if(s!=e)l=new node(s,m),r=new node(m+1,e);
}
void up(int x,int v){
if(s==x&&e==x){
if(v)++n1;
else ++n0;
return;
}
if(x<=m)l->up(x,v);
else r->up(x,v);
n0=l->n0+r->n0;
n1=l->n1+r->n1;
}
ii qry(int x,int y){
if(s==x&&e==y)return ii(n0,n1);
if(y<=m)return l->qry(x,y);
if(x>m)return r->qry(x,y);
ii pr1=l->qry(x,m);
ii pr2=r->qry(m+1,y);
return ii(pr1.fi+pr2.fi,pr1.se+pr2.se);
}
}*root;
int n,a,b;
vector<ii> v;
int col[100005];
vector<int> AL[100005];
bool dfs(int u){
bool res=true;
for(int v:AL[u]){
if(col[v]==col[u])res=false;
if(col[v]==-1){
col[v]=1-col[u];
res=res&&dfs(v);
}
}
return res;
}
int main(){
sf("%d",&n);
for(int i=0;i<n;++i){
sf("%d%d",&a,&b);
v.pb(a,b);
}
ll ans=1;
sort(all(v));
root=new node(1,2*n);
for(int i=0;i<n;++i){
ii pr=root->qry(v[i].fi,v[i].se);
//if(pr.fi&&pr.se)pf("0\n"),exit(0);
//if(pr.fi==0&&pr.se==0)ans*=2,ans%=mod;
if(pr.fi==0)root->up(v[i].se,0);
else root->up(v[i].se,1);
pr=root->qry(v[i].se,v[i].se);
}
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j){
if(v[j].fi<v[i].se&&v[i].se<v[j].se){
AL[i].pb(j);
AL[j].pb(i);
}
}
}
memset(col,-1,sizeof col);
for(int i=0;i<n;++i){
if(col[i]==-1){
col[i]=0;
if(dfs(i))ans*=2,ans%=mod;
else pf("0\n"),exit(0);
}
}
for(int i=0;i<n;++i){
ii pr=root->qry(v[i].se,v[i].se);
int c=pr.fi?0:1;
assert(col[i]==c);
}
pf("%lld\n",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
port_facility.cpp: In function 'int main()':
port_facility.cpp:62:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | sf("%d",&n);
| ^
port_facility.cpp:64:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | sf("%d%d",&a,&b);
| ^
# | 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... |