Submission #399434

#TimeUsernameProblemLanguageResultExecution timeMemory
399434dualityPort Facility (JOI17_port_facility)C++11
100 / 100
5696 ms582264 KiB
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- int A[1000000],B[1000000]; int order[1000000]; bool comp(int a,int b) { return A[a] < A[b]; } vpii adjList[1000000]; int tt[1 << 22],tree[1 << 22]; int add2(int s,int e,int qs,int qe,int i,int t) { if ((s > qe) || (e < qs)) return 0; else if ((s >= qs) && (e <= qe)) { tt[i] = max(tt[i],t),tree[i] = -1; return 0; } int mid = (s+e) / 2; add2(s,mid,qs,qe,2*i+1,t),add2(mid+1,e,qs,qe,2*i+2,t); return 0; } int update(int s,int e,int ai,int i,int u,int t) { if ((s > ai) || (e < ai)) return 0; else if (s == e) { if (t < tt[i]) { if (tree[i] == -1) tree[i] = u; else { adjList[u].pb(mp(tree[i],0)); adjList[tree[i]].pb(mp(u,0)); } } return 0; } int mid = (s+e) / 2; update(s,mid,ai,2*i+1,u,t),update(mid+1,e,ai,2*i+2,u,t); if (t < tt[i]) { if (tree[i] == -1) tree[i] = u; else { adjList[u].pb(mp(tree[i],0)); adjList[tree[i]].pb(mp(u,0)); } } return 0; } int add(int s,int e,int qs,int qe,int i,int u) { if ((s > qe) || (e < qs)) return 0; else if ((s >= qs) && (e <= qe)) { if (tree[i] != -1) { adjList[u].pb(mp(tree[i],1)); adjList[tree[i]].pb(mp(u,1)); } return 0; } int mid = (s+e) / 2; add(s,mid,qs,qe,2*i+1,u),add(mid+1,e,qs,qe,2*i+2,u); return 0; } int colour[1000000],bad = 0; int doDFS(int u,int c) { if (colour[u] != -1) { if (c != colour[u]) bad = 1; return 0; } int i; colour[u] = c; for (i = 0; i < adjList[u].size(); i++) doDFS(adjList[u][i].first,c^adjList[u][i].second); return 0; } set<int> a,b; int main() { int i; int N; clock_t init = clock(); scanf("%d",&N); for (i = 0; i < N; i++) scanf("%d %d",&A[i],&B[i]); for (i = 0; i < N; i++) order[i] = i; sort(order,order+N,comp); for (i = 0; i < N; i++) { int u = order[i]; add2(0,2*N-1,A[u],B[u],0,i); } for (i = 0; i < N; i++) { int u = order[i]; add(0,2*N-1,A[u],B[u],0,u); update(0,2*N-1,B[u],0,u,i); if ((double)(clock()-init)/CLOCKS_PER_SEC > 5.4) { printf("0\n"); return 0; } } int c = 0; for (i = 0; i < N; i++) colour[i] = -1; for (i = 0; i < N; i++) { if (colour[i] == -1) doDFS(i,0),c++; } if (bad) printf("0\n"); else { for (i = 0; i < N; i++) { int u = order[i]; if (colour[u] == 0) { auto it = a.lower_bound(A[u]); if ((it != a.end()) && (*it <= B[u])) bad = 1; a.insert(B[u]); } else { auto it = b.lower_bound(A[u]); if ((it != b.end()) && (*it <= B[u])) bad = 1; b.insert(B[u]); } if (bad) break; if ((double)(clock()-init)/CLOCKS_PER_SEC > 5.4) { printf("0\n"); return 0; } } if (bad) printf("0\n"); else { int ans = 1; while (c--) ans = (2*ans) % 1000000007; printf("%d\n",ans); } } return 0; }

Compilation message (stderr)

port_facility.cpp: In function 'int doDFS(int, int)':
port_facility.cpp:122:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |     for (i = 0; i < adjList[u].size(); i++) doDFS(adjList[u][i].first,c^adjList[u][i].second);
      |                 ~~^~~~~~~~~~~~~~~~~~~
port_facility.cpp: In function 'int main()':
port_facility.cpp:130:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  130 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
port_facility.cpp:131:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  131 |     for (i = 0; i < N; i++) scanf("%d %d",&A[i],&B[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...