이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD=1000000007;
int n;
ii arr[1000005];
vector<int> stk;
bool vis[1000005];
bool col[1000005];
struct node{
int s,e,m;
int cap=1;
int idx=0;
ii *arr=new ii[1];
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void update(int i,ii k){
if (idx==cap){
//cerr<<"debug: "<<s<<" "<<e<<" "<<cap<<endl;
ii *temp=new ii[cap*2];
memcpy(temp,arr,sizeof(arr));
arr=temp;
cap*=2;
}
arr[idx++]=k;
if (s==e) return;
if (i<=m) l->update(i,k);
else r->update(i,k);
}
ii query(int i,int j){
if (s==i && e==j){
while (idx && vis[arr[idx-1].se]) idx-=1;
if (idx) return arr[idx-1];
else return ii(-1e9,-1e9);
}
else if (j<=m) return l->query(i,j);
else if (m<i) return r->query(i,j);
else return max(l->query(i,m),r->query(m+1,j));
}
} *root=new node(0,2000005), *root2=new node(0,2000005);
struct node2{
int arr[4000010];
const int BUF=2000005;
node2(){
memset(arr,-1,sizeof(arr));
}
void update(int i,int k){
i+=BUF;
while (i){
arr[i]=max(arr[i],k);
i>>=1;
}
}
int query(int i,int j){
i+=BUF,j+=BUF+1;
int res=-1;
for (;i<j;i>>=1,j>>=1){
if (i&1){
res=max(res,arr[i]);
i++;
}
if (j&1){
j--;
res=max(res,arr[j]);
}
}
return res;
}
} *white=new node2(),*black=new node2();
int ans=1;
int main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n;
rep(x,0,n) cin>>arr[x].fi>>arr[x].se;
vector<int> proc;
rep(x,0,n) proc.pub(x);
sort(all(proc),[](int i,int j){
return arr[i].se<arr[j].se;
});
for (auto &it:proc) root->update(arr[it].fi,ii(arr[it].se,it));
sort(all(proc),[](int i,int j){
return arr[i].fi>arr[j].fi;
});
for (auto &it:proc) root2->update(arr[it].se,ii(-arr[it].fi,it));
rep(x,0,n) if (!vis[x]){
vis[x]=true;
stk.pub(x);
ans=2*ans%MOD;
while (!stk.empty()){
int pos=stk.back();
stk.pob();
//cout<<pos<<" "<<col[pos]<<endl;
if (!col[pos]){
white->update(arr[pos].fi,arr[pos].se);
}
else{
black->update(arr[pos].fi,arr[pos].se);
}
while (true){
int it=root->query(arr[pos].fi,arr[pos].se).se;
if (it==-1e9 || arr[it].se<arr[pos].se) break;
vis[it]=true;
stk.pub(it);
col[it]=!col[pos];
}
while (true){
int it=root2->query(arr[pos].fi,arr[pos].se).se;
if (it==-1e9 || arr[it].fi>arr[pos].fi) break;
vis[it]=true;
stk.pub(it);
col[it]=!col[pos];
}
}
}
rep(x,0,n){
if (!col[x]){ //white
if (white->query(arr[x].fi,arr[x].se)>arr[x].se) ans=0;
}
else{ //black
if (black->query(arr[x].fi,arr[x].se)>arr[x].se) ans=0;
}
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
port_facility.cpp: In constructor 'node::node(int, int)':
port_facility.cpp:40:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | s=_s,e=_e,m=s+e>>1;
| ~^~
port_facility.cpp: In member function 'void node::update(int, std::pair<int, int>)':
port_facility.cpp:53:20: warning: argument to 'sizeof' in 'void* memcpy(void*, const void*, size_t)' call is the same pointer type 'std::pair<int, int>*' as the destination; expected 'std::pair<int, int>' or an explicit length [-Wsizeof-pointer-memaccess]
53 | memcpy(temp,arr,sizeof(arr));
| ^~~~~~~~~~~
port_facility.cpp:53:31: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct std::pair<int, int>' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
53 | memcpy(temp,arr,sizeof(arr));
| ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
from /usr/include/c++/10/bits/specfun.h:45,
from /usr/include/c++/10/cmath:1927,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
from port_facility.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<int, int>' declared here
211 | struct pair
| ^~~~
# | 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... |