/*
*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
///#define ll long long
typedef pair<int,int> pii;
const int maxn=1e6+10;
int mod=1e9+7,e;
int levi[maxn],color[maxn],n,kolko,rez,grane;
pii niz[2*maxn];
vector<int>vect[maxn];
set<int>tree[(1<<22)+10];
void update(int x,int l,int r,int id,int val,int tip){
if(tip)tree[x].insert(val);
else tree[x].erase(val);
if(l==r)return;
int mid=(l+r)/2;
if(id<=mid)update(x*2,l,mid,id,val,tip);
else update(x*2+1,mid+1,r,id,val,tip);
}
void go(int x,int l,int r,int ll,int rr,int nd){
if(l>=ll && r<=rr){
for(set<int>::iterator it=tree[x].begin();it!=tree[x].end();it++){
int id=(*it);
vect[nd].pb(id);
vect[id].pb(nd);
grane++;
/// printf("%d IDID\n",id);
}
return;
}
int mid=(l+r)/2;
if(ll>mid)go(x*2+1,mid+1,r,ll,rr,nd);
else if(rr<=mid)go(x*2,l,mid,ll,rr,nd);
else{
go(x*2,l,mid,ll,rr,nd);
go(x*2+1,mid+1,r,ll,rr,nd);
}
}
void dfs(int x,int col){
color[x]=col;
for(int i=0;i<vect[x].size();i++){
int id=vect[x][i];
if(color[id]==col)rez=0;
else if(color[id]==-1)dfs(id,col^1);
}
}
int main(){
///freopen("test.txt","r",stdin);
scanf("%d",&n);
int limit=10000000;
if(n<=2000)limit=1e9;
memset(color,-1,sizeof(color));
for(int i=1;i<=n;i++){
int a,b;
scanf("%d %d",&a,&b);
niz[a]={i,1};
niz[b]={i,-1};
levi[i]=a;
}
for(int i=1;i<=2*n;i++){
if(niz[i].ss>0)update(1,1,2*n,i,niz[i].ff,1);
else{
int id=niz[i].ff;
int lb=levi[id];
update(1,1,2*n,lb,id,0);
///printf("%d AAAAA\n",id);
go(1,1,2*n,lb,i,id);
if(grane>limit){
printf("0\n");
return 0;
}
}
}
rez=1;
for(int i=1;i<=n;i++){
if(color[i]==-1){
dfs(i,0);
rez+=rez;
if(rez>=mod)rez-=mod;
}
}
printf("%d\n",rez);
return 0;
}
Compilation message
port_facility.cpp: In function 'void dfs(int, int)':
port_facility.cpp:55:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<vect[x].size();i++){
~^~~~~~~~~~~~~~~
port_facility.cpp: In function 'int main()':
port_facility.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
port_facility.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a,&b);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
224760 KB |
Output is correct |
2 |
Correct |
132 ms |
224760 KB |
Output is correct |
3 |
Correct |
132 ms |
224760 KB |
Output is correct |
4 |
Correct |
125 ms |
224760 KB |
Output is correct |
5 |
Correct |
127 ms |
224760 KB |
Output is correct |
6 |
Correct |
131 ms |
224760 KB |
Output is correct |
7 |
Correct |
128 ms |
224760 KB |
Output is correct |
8 |
Correct |
129 ms |
224728 KB |
Output is correct |
9 |
Correct |
130 ms |
224760 KB |
Output is correct |
10 |
Correct |
127 ms |
224760 KB |
Output is correct |
11 |
Correct |
126 ms |
224760 KB |
Output is correct |
12 |
Correct |
124 ms |
224760 KB |
Output is correct |
13 |
Correct |
124 ms |
224760 KB |
Output is correct |
14 |
Correct |
125 ms |
224764 KB |
Output is correct |
15 |
Correct |
124 ms |
224760 KB |
Output is correct |
16 |
Correct |
129 ms |
224776 KB |
Output is correct |
17 |
Correct |
137 ms |
224840 KB |
Output is correct |
18 |
Correct |
124 ms |
224760 KB |
Output is correct |
19 |
Correct |
126 ms |
224728 KB |
Output is correct |
20 |
Correct |
121 ms |
224760 KB |
Output is correct |
21 |
Correct |
129 ms |
224760 KB |
Output is correct |
22 |
Correct |
127 ms |
224760 KB |
Output is correct |
23 |
Correct |
125 ms |
224784 KB |
Output is correct |
24 |
Correct |
121 ms |
224760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
224760 KB |
Output is correct |
2 |
Correct |
132 ms |
224760 KB |
Output is correct |
3 |
Correct |
132 ms |
224760 KB |
Output is correct |
4 |
Correct |
125 ms |
224760 KB |
Output is correct |
5 |
Correct |
127 ms |
224760 KB |
Output is correct |
6 |
Correct |
131 ms |
224760 KB |
Output is correct |
7 |
Correct |
128 ms |
224760 KB |
Output is correct |
8 |
Correct |
129 ms |
224728 KB |
Output is correct |
9 |
Correct |
130 ms |
224760 KB |
Output is correct |
10 |
Correct |
127 ms |
224760 KB |
Output is correct |
11 |
Correct |
126 ms |
224760 KB |
Output is correct |
12 |
Correct |
124 ms |
224760 KB |
Output is correct |
13 |
Correct |
124 ms |
224760 KB |
Output is correct |
14 |
Correct |
125 ms |
224764 KB |
Output is correct |
15 |
Correct |
124 ms |
224760 KB |
Output is correct |
16 |
Correct |
129 ms |
224776 KB |
Output is correct |
17 |
Correct |
137 ms |
224840 KB |
Output is correct |
18 |
Correct |
124 ms |
224760 KB |
Output is correct |
19 |
Correct |
126 ms |
224728 KB |
Output is correct |
20 |
Correct |
121 ms |
224760 KB |
Output is correct |
21 |
Correct |
129 ms |
224760 KB |
Output is correct |
22 |
Correct |
127 ms |
224760 KB |
Output is correct |
23 |
Correct |
125 ms |
224784 KB |
Output is correct |
24 |
Correct |
121 ms |
224760 KB |
Output is correct |
25 |
Correct |
129 ms |
225528 KB |
Output is correct |
26 |
Correct |
129 ms |
225528 KB |
Output is correct |
27 |
Correct |
134 ms |
225528 KB |
Output is correct |
28 |
Correct |
133 ms |
225528 KB |
Output is correct |
29 |
Correct |
133 ms |
225528 KB |
Output is correct |
30 |
Correct |
131 ms |
225528 KB |
Output is correct |
31 |
Correct |
136 ms |
225564 KB |
Output is correct |
32 |
Correct |
129 ms |
225528 KB |
Output is correct |
33 |
Correct |
128 ms |
225528 KB |
Output is correct |
34 |
Correct |
132 ms |
225528 KB |
Output is correct |
35 |
Correct |
123 ms |
224760 KB |
Output is correct |
36 |
Correct |
129 ms |
225912 KB |
Output is correct |
37 |
Correct |
228 ms |
242296 KB |
Output is correct |
38 |
Correct |
177 ms |
233320 KB |
Output is correct |
39 |
Correct |
132 ms |
224888 KB |
Output is correct |
40 |
Correct |
126 ms |
224760 KB |
Output is correct |
41 |
Correct |
166 ms |
233592 KB |
Output is correct |
42 |
Correct |
167 ms |
233636 KB |
Output is correct |
43 |
Correct |
126 ms |
225016 KB |
Output is correct |
44 |
Correct |
127 ms |
224872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
224760 KB |
Output is correct |
2 |
Correct |
132 ms |
224760 KB |
Output is correct |
3 |
Correct |
132 ms |
224760 KB |
Output is correct |
4 |
Correct |
125 ms |
224760 KB |
Output is correct |
5 |
Correct |
127 ms |
224760 KB |
Output is correct |
6 |
Correct |
131 ms |
224760 KB |
Output is correct |
7 |
Correct |
128 ms |
224760 KB |
Output is correct |
8 |
Correct |
129 ms |
224728 KB |
Output is correct |
9 |
Correct |
130 ms |
224760 KB |
Output is correct |
10 |
Correct |
127 ms |
224760 KB |
Output is correct |
11 |
Correct |
126 ms |
224760 KB |
Output is correct |
12 |
Correct |
124 ms |
224760 KB |
Output is correct |
13 |
Correct |
124 ms |
224760 KB |
Output is correct |
14 |
Correct |
125 ms |
224764 KB |
Output is correct |
15 |
Correct |
124 ms |
224760 KB |
Output is correct |
16 |
Correct |
129 ms |
224776 KB |
Output is correct |
17 |
Correct |
137 ms |
224840 KB |
Output is correct |
18 |
Correct |
124 ms |
224760 KB |
Output is correct |
19 |
Correct |
126 ms |
224728 KB |
Output is correct |
20 |
Correct |
121 ms |
224760 KB |
Output is correct |
21 |
Correct |
129 ms |
224760 KB |
Output is correct |
22 |
Correct |
127 ms |
224760 KB |
Output is correct |
23 |
Correct |
125 ms |
224784 KB |
Output is correct |
24 |
Correct |
121 ms |
224760 KB |
Output is correct |
25 |
Correct |
129 ms |
225528 KB |
Output is correct |
26 |
Correct |
129 ms |
225528 KB |
Output is correct |
27 |
Correct |
134 ms |
225528 KB |
Output is correct |
28 |
Correct |
133 ms |
225528 KB |
Output is correct |
29 |
Correct |
133 ms |
225528 KB |
Output is correct |
30 |
Correct |
131 ms |
225528 KB |
Output is correct |
31 |
Correct |
136 ms |
225564 KB |
Output is correct |
32 |
Correct |
129 ms |
225528 KB |
Output is correct |
33 |
Correct |
128 ms |
225528 KB |
Output is correct |
34 |
Correct |
132 ms |
225528 KB |
Output is correct |
35 |
Correct |
123 ms |
224760 KB |
Output is correct |
36 |
Correct |
129 ms |
225912 KB |
Output is correct |
37 |
Correct |
228 ms |
242296 KB |
Output is correct |
38 |
Correct |
177 ms |
233320 KB |
Output is correct |
39 |
Correct |
132 ms |
224888 KB |
Output is correct |
40 |
Correct |
126 ms |
224760 KB |
Output is correct |
41 |
Correct |
166 ms |
233592 KB |
Output is correct |
42 |
Correct |
167 ms |
233636 KB |
Output is correct |
43 |
Correct |
126 ms |
225016 KB |
Output is correct |
44 |
Correct |
127 ms |
224872 KB |
Output is correct |
45 |
Correct |
972 ms |
272872 KB |
Output is correct |
46 |
Correct |
1174 ms |
300792 KB |
Output is correct |
47 |
Correct |
874 ms |
272504 KB |
Output is correct |
48 |
Correct |
1164 ms |
299000 KB |
Output is correct |
49 |
Correct |
911 ms |
272380 KB |
Output is correct |
50 |
Correct |
1194 ms |
299056 KB |
Output is correct |
51 |
Correct |
1012 ms |
273400 KB |
Output is correct |
52 |
Correct |
282 ms |
226680 KB |
Output is correct |
53 |
Correct |
1078 ms |
314568 KB |
Output is correct |
54 |
Correct |
2719 ms |
407284 KB |
Output is correct |
55 |
Correct |
2260 ms |
363180 KB |
Output is correct |
56 |
Correct |
2232 ms |
363116 KB |
Output is correct |
57 |
Correct |
337 ms |
231048 KB |
Output is correct |
58 |
Correct |
312 ms |
228092 KB |
Output is correct |
59 |
Correct |
650 ms |
257632 KB |
Output is correct |
60 |
Correct |
691 ms |
258284 KB |
Output is correct |
61 |
Correct |
808 ms |
258936 KB |
Output is correct |
62 |
Correct |
763 ms |
257740 KB |
Output is correct |
63 |
Correct |
770 ms |
258936 KB |
Output is correct |
64 |
Correct |
810 ms |
259320 KB |
Output is correct |
65 |
Correct |
2328 ms |
373788 KB |
Output is correct |
66 |
Correct |
2318 ms |
373600 KB |
Output is correct |
67 |
Incorrect |
1427 ms |
374012 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
224760 KB |
Output is correct |
2 |
Correct |
132 ms |
224760 KB |
Output is correct |
3 |
Correct |
132 ms |
224760 KB |
Output is correct |
4 |
Correct |
125 ms |
224760 KB |
Output is correct |
5 |
Correct |
127 ms |
224760 KB |
Output is correct |
6 |
Correct |
131 ms |
224760 KB |
Output is correct |
7 |
Correct |
128 ms |
224760 KB |
Output is correct |
8 |
Correct |
129 ms |
224728 KB |
Output is correct |
9 |
Correct |
130 ms |
224760 KB |
Output is correct |
10 |
Correct |
127 ms |
224760 KB |
Output is correct |
11 |
Correct |
126 ms |
224760 KB |
Output is correct |
12 |
Correct |
124 ms |
224760 KB |
Output is correct |
13 |
Correct |
124 ms |
224760 KB |
Output is correct |
14 |
Correct |
125 ms |
224764 KB |
Output is correct |
15 |
Correct |
124 ms |
224760 KB |
Output is correct |
16 |
Correct |
129 ms |
224776 KB |
Output is correct |
17 |
Correct |
137 ms |
224840 KB |
Output is correct |
18 |
Correct |
124 ms |
224760 KB |
Output is correct |
19 |
Correct |
126 ms |
224728 KB |
Output is correct |
20 |
Correct |
121 ms |
224760 KB |
Output is correct |
21 |
Correct |
129 ms |
224760 KB |
Output is correct |
22 |
Correct |
127 ms |
224760 KB |
Output is correct |
23 |
Correct |
125 ms |
224784 KB |
Output is correct |
24 |
Correct |
121 ms |
224760 KB |
Output is correct |
25 |
Correct |
129 ms |
225528 KB |
Output is correct |
26 |
Correct |
129 ms |
225528 KB |
Output is correct |
27 |
Correct |
134 ms |
225528 KB |
Output is correct |
28 |
Correct |
133 ms |
225528 KB |
Output is correct |
29 |
Correct |
133 ms |
225528 KB |
Output is correct |
30 |
Correct |
131 ms |
225528 KB |
Output is correct |
31 |
Correct |
136 ms |
225564 KB |
Output is correct |
32 |
Correct |
129 ms |
225528 KB |
Output is correct |
33 |
Correct |
128 ms |
225528 KB |
Output is correct |
34 |
Correct |
132 ms |
225528 KB |
Output is correct |
35 |
Correct |
123 ms |
224760 KB |
Output is correct |
36 |
Correct |
129 ms |
225912 KB |
Output is correct |
37 |
Correct |
228 ms |
242296 KB |
Output is correct |
38 |
Correct |
177 ms |
233320 KB |
Output is correct |
39 |
Correct |
132 ms |
224888 KB |
Output is correct |
40 |
Correct |
126 ms |
224760 KB |
Output is correct |
41 |
Correct |
166 ms |
233592 KB |
Output is correct |
42 |
Correct |
167 ms |
233636 KB |
Output is correct |
43 |
Correct |
126 ms |
225016 KB |
Output is correct |
44 |
Correct |
127 ms |
224872 KB |
Output is correct |
45 |
Correct |
972 ms |
272872 KB |
Output is correct |
46 |
Correct |
1174 ms |
300792 KB |
Output is correct |
47 |
Correct |
874 ms |
272504 KB |
Output is correct |
48 |
Correct |
1164 ms |
299000 KB |
Output is correct |
49 |
Correct |
911 ms |
272380 KB |
Output is correct |
50 |
Correct |
1194 ms |
299056 KB |
Output is correct |
51 |
Correct |
1012 ms |
273400 KB |
Output is correct |
52 |
Correct |
282 ms |
226680 KB |
Output is correct |
53 |
Correct |
1078 ms |
314568 KB |
Output is correct |
54 |
Correct |
2719 ms |
407284 KB |
Output is correct |
55 |
Correct |
2260 ms |
363180 KB |
Output is correct |
56 |
Correct |
2232 ms |
363116 KB |
Output is correct |
57 |
Correct |
337 ms |
231048 KB |
Output is correct |
58 |
Correct |
312 ms |
228092 KB |
Output is correct |
59 |
Correct |
650 ms |
257632 KB |
Output is correct |
60 |
Correct |
691 ms |
258284 KB |
Output is correct |
61 |
Correct |
808 ms |
258936 KB |
Output is correct |
62 |
Correct |
763 ms |
257740 KB |
Output is correct |
63 |
Correct |
770 ms |
258936 KB |
Output is correct |
64 |
Correct |
810 ms |
259320 KB |
Output is correct |
65 |
Correct |
2328 ms |
373788 KB |
Output is correct |
66 |
Correct |
2318 ms |
373600 KB |
Output is correct |
67 |
Incorrect |
1427 ms |
374012 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |