Submission #28211

#TimeUsernameProblemLanguageResultExecution timeMemory
28211top34051Port Facility (JOI17_port_facility)C++14
100 / 100
2013 ms74152 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...