Submission #28211

# Submission time Handle Problem Language Result Execution time Memory
28211 2017-07-15T18:45:10 Z top34051 Port Facility (JOI17_port_facility) C++14
100 / 100
2013 ms 74152 KB
#include<bits/stdc++.h>
using namespace std;
#define maxn 1000005
#define mod 1000000007LL
int n;
int head[maxn*2];
bool check[maxn*2];
pair<int,int> p[maxn];
map<int,int> pos;
int findhead(int x) {
    if(x==head[x]) return x;
    return head[x] = findhead(head[x]);
}
void fus(int x,int y) {
    head[findhead(x)] = findhead(y);
}
main() {
    int i;
    long long ans;
    map<int,int>::iterator st,ft;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d%d",&p[i].first,&p[i].second);
    sort(&p[0],&p[n]);
    for(i=0;i<n*2;i++) head[i] = i;
    for(i=0;i<n;i++) {
        st = pos.lower_bound(p[i].first);
        ft = pos.lower_bound(p[i].second);
        while(st!=ft) {
            fus(i,st->second+n); fus(i+n,st->second);
            if(findhead(st->second)==findhead((--ft)->second)) break;
            ++ft;
            st++;
        }
        pos[p[i].second] = i;
    }
    ans = 1;
    for(i=0;i<n;i++) {
        if(findhead(i)==findhead(i+n)) ans = 0;
        else check[findhead(i)] = check[findhead(i+n)] = 1;
    }
    for(i=0;i<n;i++) if(check[i]) ans = (ans*2)%mod;
    printf("%lld",ans);
}

Compilation message

port_facility.cpp:17:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
port_facility.cpp: In function 'int main()':
port_facility.cpp:21:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
port_facility.cpp:22:60: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=0;i<n;i++) scanf("%d%d",&p[i].first,&p[i].second);
                                                            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 19600 KB Output is correct
2 Correct 0 ms 19600 KB Output is correct
3 Correct 0 ms 19600 KB Output is correct
4 Correct 0 ms 19600 KB Output is correct
5 Correct 0 ms 19600 KB Output is correct
6 Correct 0 ms 19600 KB Output is correct
7 Correct 0 ms 19600 KB Output is correct
8 Correct 0 ms 19600 KB Output is correct
9 Correct 0 ms 19600 KB Output is correct
10 Correct 0 ms 19600 KB Output is correct
11 Correct 0 ms 19600 KB Output is correct
12 Correct 0 ms 19600 KB Output is correct
13 Correct 0 ms 19600 KB Output is correct
14 Correct 0 ms 19600 KB Output is correct
15 Correct 0 ms 19600 KB Output is correct
16 Correct 0 ms 19600 KB Output is correct
17 Correct 0 ms 19600 KB Output is correct
18 Correct 0 ms 19600 KB Output is correct
19 Correct 0 ms 19600 KB Output is correct
20 Correct 0 ms 19600 KB Output is correct
21 Correct 0 ms 19600 KB Output is correct
22 Correct 0 ms 19600 KB Output is correct
23 Correct 0 ms 19600 KB Output is correct
24 Correct 0 ms 19600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 19600 KB Output is correct
2 Correct 0 ms 19600 KB Output is correct
3 Correct 0 ms 19600 KB Output is correct
4 Correct 0 ms 19600 KB Output is correct
5 Correct 0 ms 19600 KB Output is correct
6 Correct 0 ms 19600 KB Output is correct
7 Correct 0 ms 19600 KB Output is correct
8 Correct 0 ms 19600 KB Output is correct
9 Correct 0 ms 19600 KB Output is correct
10 Correct 0 ms 19600 KB Output is correct
11 Correct 0 ms 19600 KB Output is correct
12 Correct 0 ms 19600 KB Output is correct
13 Correct 0 ms 19600 KB Output is correct
14 Correct 0 ms 19600 KB Output is correct
15 Correct 0 ms 19600 KB Output is correct
16 Correct 0 ms 19600 KB Output is correct
17 Correct 0 ms 19600 KB Output is correct
18 Correct 0 ms 19600 KB Output is correct
19 Correct 0 ms 19600 KB Output is correct
20 Correct 0 ms 19600 KB Output is correct
21 Correct 0 ms 19600 KB Output is correct
22 Correct 0 ms 19600 KB Output is correct
23 Correct 0 ms 19600 KB Output is correct
24 Correct 0 ms 19600 KB Output is correct
25 Correct 0 ms 19732 KB Output is correct
26 Correct 0 ms 19732 KB Output is correct
27 Correct 0 ms 19732 KB Output is correct
28 Correct 0 ms 19732 KB Output is correct
29 Correct 0 ms 19732 KB Output is correct
30 Correct 0 ms 19732 KB Output is correct
31 Correct 0 ms 19732 KB Output is correct
32 Correct 0 ms 19732 KB Output is correct
33 Correct 0 ms 19732 KB Output is correct
34 Correct 0 ms 19732 KB Output is correct
35 Correct 0 ms 19732 KB Output is correct
36 Correct 0 ms 19732 KB Output is correct
37 Correct 0 ms 19732 KB Output is correct
38 Correct 0 ms 19732 KB Output is correct
39 Correct 0 ms 19732 KB Output is correct
40 Correct 0 ms 19732 KB Output is correct
41 Correct 0 ms 19732 KB Output is correct
42 Correct 0 ms 19732 KB Output is correct
43 Correct 0 ms 19732 KB Output is correct
44 Correct 0 ms 19732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 19600 KB Output is correct
2 Correct 0 ms 19600 KB Output is correct
3 Correct 0 ms 19600 KB Output is correct
4 Correct 0 ms 19600 KB Output is correct
5 Correct 0 ms 19600 KB Output is correct
6 Correct 0 ms 19600 KB Output is correct
7 Correct 0 ms 19600 KB Output is correct
8 Correct 0 ms 19600 KB Output is correct
9 Correct 0 ms 19600 KB Output is correct
10 Correct 0 ms 19600 KB Output is correct
11 Correct 0 ms 19600 KB Output is correct
12 Correct 0 ms 19600 KB Output is correct
13 Correct 0 ms 19600 KB Output is correct
14 Correct 0 ms 19600 KB Output is correct
15 Correct 0 ms 19600 KB Output is correct
16 Correct 0 ms 19600 KB Output is correct
17 Correct 0 ms 19600 KB Output is correct
18 Correct 0 ms 19600 KB Output is correct
19 Correct 0 ms 19600 KB Output is correct
20 Correct 0 ms 19600 KB Output is correct
21 Correct 0 ms 19600 KB Output is correct
22 Correct 0 ms 19600 KB Output is correct
23 Correct 0 ms 19600 KB Output is correct
24 Correct 0 ms 19600 KB Output is correct
25 Correct 0 ms 19732 KB Output is correct
26 Correct 0 ms 19732 KB Output is correct
27 Correct 0 ms 19732 KB Output is correct
28 Correct 0 ms 19732 KB Output is correct
29 Correct 0 ms 19732 KB Output is correct
30 Correct 0 ms 19732 KB Output is correct
31 Correct 0 ms 19732 KB Output is correct
32 Correct 0 ms 19732 KB Output is correct
33 Correct 0 ms 19732 KB Output is correct
34 Correct 0 ms 19732 KB Output is correct
35 Correct 0 ms 19732 KB Output is correct
36 Correct 0 ms 19732 KB Output is correct
37 Correct 0 ms 19732 KB Output is correct
38 Correct 0 ms 19732 KB Output is correct
39 Correct 0 ms 19732 KB Output is correct
40 Correct 0 ms 19732 KB Output is correct
41 Correct 0 ms 19732 KB Output is correct
42 Correct 0 ms 19732 KB Output is correct
43 Correct 0 ms 19732 KB Output is correct
44 Correct 0 ms 19732 KB Output is correct
45 Correct 83 ms 24352 KB Output is correct
46 Correct 83 ms 24352 KB Output is correct
47 Correct 86 ms 24352 KB Output is correct
48 Correct 79 ms 24352 KB Output is correct
49 Correct 76 ms 24352 KB Output is correct
50 Correct 79 ms 24352 KB Output is correct
51 Correct 96 ms 24352 KB Output is correct
52 Correct 89 ms 24352 KB Output is correct
53 Correct 86 ms 24352 KB Output is correct
54 Correct 76 ms 24352 KB Output is correct
55 Correct 69 ms 24352 KB Output is correct
56 Correct 76 ms 24352 KB Output is correct
57 Correct 83 ms 24352 KB Output is correct
58 Correct 89 ms 24352 KB Output is correct
59 Correct 83 ms 24352 KB Output is correct
60 Correct 83 ms 24352 KB Output is correct
61 Correct 79 ms 24352 KB Output is correct
62 Correct 76 ms 24352 KB Output is correct
63 Correct 79 ms 24352 KB Output is correct
64 Correct 83 ms 24352 KB Output is correct
65 Correct 106 ms 24352 KB Output is correct
66 Correct 106 ms 24352 KB Output is correct
67 Correct 86 ms 25008 KB Output is correct
68 Correct 89 ms 25008 KB Output is correct
69 Correct 86 ms 24744 KB Output is correct
70 Correct 93 ms 24744 KB Output is correct
71 Correct 93 ms 25008 KB Output is correct
72 Correct 96 ms 25012 KB Output is correct
73 Correct 99 ms 24744 KB Output is correct
74 Correct 93 ms 24748 KB Output is correct
75 Correct 89 ms 24352 KB Output is correct
76 Correct 93 ms 24352 KB Output is correct
77 Correct 93 ms 24352 KB Output is correct
78 Correct 89 ms 24352 KB Output is correct
79 Correct 83 ms 24352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 19600 KB Output is correct
2 Correct 0 ms 19600 KB Output is correct
3 Correct 0 ms 19600 KB Output is correct
4 Correct 0 ms 19600 KB Output is correct
5 Correct 0 ms 19600 KB Output is correct
6 Correct 0 ms 19600 KB Output is correct
7 Correct 0 ms 19600 KB Output is correct
8 Correct 0 ms 19600 KB Output is correct
9 Correct 0 ms 19600 KB Output is correct
10 Correct 0 ms 19600 KB Output is correct
11 Correct 0 ms 19600 KB Output is correct
12 Correct 0 ms 19600 KB Output is correct
13 Correct 0 ms 19600 KB Output is correct
14 Correct 0 ms 19600 KB Output is correct
15 Correct 0 ms 19600 KB Output is correct
16 Correct 0 ms 19600 KB Output is correct
17 Correct 0 ms 19600 KB Output is correct
18 Correct 0 ms 19600 KB Output is correct
19 Correct 0 ms 19600 KB Output is correct
20 Correct 0 ms 19600 KB Output is correct
21 Correct 0 ms 19600 KB Output is correct
22 Correct 0 ms 19600 KB Output is correct
23 Correct 0 ms 19600 KB Output is correct
24 Correct 0 ms 19600 KB Output is correct
25 Correct 0 ms 19732 KB Output is correct
26 Correct 0 ms 19732 KB Output is correct
27 Correct 0 ms 19732 KB Output is correct
28 Correct 0 ms 19732 KB Output is correct
29 Correct 0 ms 19732 KB Output is correct
30 Correct 0 ms 19732 KB Output is correct
31 Correct 0 ms 19732 KB Output is correct
32 Correct 0 ms 19732 KB Output is correct
33 Correct 0 ms 19732 KB Output is correct
34 Correct 0 ms 19732 KB Output is correct
35 Correct 0 ms 19732 KB Output is correct
36 Correct 0 ms 19732 KB Output is correct
37 Correct 0 ms 19732 KB Output is correct
38 Correct 0 ms 19732 KB Output is correct
39 Correct 0 ms 19732 KB Output is correct
40 Correct 0 ms 19732 KB Output is correct
41 Correct 0 ms 19732 KB Output is correct
42 Correct 0 ms 19732 KB Output is correct
43 Correct 0 ms 19732 KB Output is correct
44 Correct 0 ms 19732 KB Output is correct
45 Correct 83 ms 24352 KB Output is correct
46 Correct 83 ms 24352 KB Output is correct
47 Correct 86 ms 24352 KB Output is correct
48 Correct 79 ms 24352 KB Output is correct
49 Correct 76 ms 24352 KB Output is correct
50 Correct 79 ms 24352 KB Output is correct
51 Correct 96 ms 24352 KB Output is correct
52 Correct 89 ms 24352 KB Output is correct
53 Correct 86 ms 24352 KB Output is correct
54 Correct 76 ms 24352 KB Output is correct
55 Correct 69 ms 24352 KB Output is correct
56 Correct 76 ms 24352 KB Output is correct
57 Correct 83 ms 24352 KB Output is correct
58 Correct 89 ms 24352 KB Output is correct
59 Correct 83 ms 24352 KB Output is correct
60 Correct 83 ms 24352 KB Output is correct
61 Correct 79 ms 24352 KB Output is correct
62 Correct 76 ms 24352 KB Output is correct
63 Correct 79 ms 24352 KB Output is correct
64 Correct 83 ms 24352 KB Output is correct
65 Correct 106 ms 24352 KB Output is correct
66 Correct 106 ms 24352 KB Output is correct
67 Correct 86 ms 25008 KB Output is correct
68 Correct 89 ms 25008 KB Output is correct
69 Correct 86 ms 24744 KB Output is correct
70 Correct 93 ms 24744 KB Output is correct
71 Correct 93 ms 25008 KB Output is correct
72 Correct 96 ms 25012 KB Output is correct
73 Correct 99 ms 24744 KB Output is correct
74 Correct 93 ms 24748 KB Output is correct
75 Correct 89 ms 24352 KB Output is correct
76 Correct 93 ms 24352 KB Output is correct
77 Correct 93 ms 24352 KB Output is correct
78 Correct 89 ms 24352 KB Output is correct
79 Correct 83 ms 24352 KB Output is correct
80 Correct 946 ms 66460 KB Output is correct
81 Correct 953 ms 66460 KB Output is correct
82 Correct 979 ms 66460 KB Output is correct
83 Correct 913 ms 66460 KB Output is correct
84 Correct 933 ms 66460 KB Output is correct
85 Correct 926 ms 66460 KB Output is correct
86 Correct 933 ms 66460 KB Output is correct
87 Correct 1176 ms 66460 KB Output is correct
88 Correct 1233 ms 66460 KB Output is correct
89 Correct 1169 ms 66460 KB Output is correct
90 Correct 1123 ms 66460 KB Output is correct
91 Correct 1053 ms 66460 KB Output is correct
92 Correct 1193 ms 66460 KB Output is correct
93 Correct 1146 ms 66460 KB Output is correct
94 Correct 826 ms 66460 KB Output is correct
95 Correct 936 ms 66460 KB Output is correct
96 Correct 899 ms 66460 KB Output is correct
97 Correct 796 ms 66460 KB Output is correct
98 Correct 936 ms 66460 KB Output is correct
99 Correct 863 ms 66460 KB Output is correct
100 Correct 1926 ms 66460 KB Output is correct
101 Correct 2013 ms 66460 KB Output is correct
102 Correct 1339 ms 74152 KB Output is correct
103 Correct 1246 ms 74148 KB Output is correct
104 Correct 1246 ms 71548 KB Output is correct
105 Correct 1253 ms 71540 KB Output is correct
106 Correct 1359 ms 74148 KB Output is correct
107 Correct 1376 ms 74152 KB Output is correct
108 Correct 1349 ms 71540 KB Output is correct
109 Correct 1429 ms 71540 KB Output is correct
110 Correct 1253 ms 66460 KB Output is correct
111 Correct 1293 ms 66460 KB Output is correct
112 Correct 1263 ms 66460 KB Output is correct
113 Correct 913 ms 66460 KB Output is correct
114 Correct 973 ms 66460 KB Output is correct