Submission #333680

#TimeUsernameProblemLanguageResultExecution timeMemory
333680CaroLindaPort Facility (JOI17_port_facility)C++14
78 / 100
6136 ms756080 KiB
#include <bits/stdc++.h> #define debug printf #define all(x) x.begin(),x.end() #define sz(x) (int)(x.size() ) #define ll long long const int MAX = 2e6+10 ; const int MOD = 1e9+7 ; using namespace std ; int m(int l, int r ) { return (l+r)>>1 ; } int N ; int L[MAX] , R[MAX] ; int color[MAX] ; vector<int> byEnd[MAX*4] , byBeginning[MAX*4] ; void makeInsertion( int pos, int l, int r, int x, int id , bool isEnd ) { if(isEnd) byEnd[pos].push_back( id ) ; else byBeginning[pos].push_back(id) ; if( l == r) return ; if( x <= m(l,r) ) makeInsertion(pos<<1 , l , m(l,r) , x , id , isEnd ) ; else makeInsertion( pos<<1|1 , m(l,r)+1, r, x, id, isEnd ) ; } void walk(int pos, int l, int r, int id , vector<int> &fila ) { if( l > R[id] || r < L[id] ) return ; if( l >= L[id] && r <= R[id] ) { vector<int> &aux1 = byBeginning[pos] ; while( !aux1.empty() && L[aux1.back() ] < L[id] ) { if( color[ aux1.back() ] == -1 ) { fila.push_back( aux1.back() ); color[ aux1.back() ] = !color[id] ; } aux1.pop_back() ; } vector<int> &aux2 = byEnd[pos] ; while( !aux2.empty() && R[ aux2.back() ] > R[id] ) { if( color[ aux2.back() ] == -1 ) { fila.push_back( aux2.back() ) ; color[ aux2.back() ] = !color[id] ; } aux2.pop_back() ; } return ; } walk(pos<<1 , l , m(l,r) , id, fila ) ; walk(pos<<1|1 , m(l,r) + 1 , r , id , fila ) ; } int main() { scanf("%d", &N ) ; for(int i=1 ; i <= N ; i++ ) scanf("%d %d", &L[i] , &R[i] ) ; //By beginning vector<int> toSort(N) ; iota(all(toSort), 1) ; sort( all(toSort) , [&](int i, int j) { return L[i] > L[j] ; } ) ; for(int i = 0 ; i < N ; i++ ) makeInsertion(1,1,2*N, R[ toSort[i] ], toSort[i], false ) ; //By end sort(all(toSort), [&](int i, int j) { return R[i] < R[j] ; } ) ; for(int i = 0 ; i < N ; i++ ) makeInsertion(1, 1, 2*N, L[ toSort[i] ], toSort[i] , true ) ; for(int i = 1 ; i <= N ; i++ ) color[i] = -1 ; int ans = 1 ; for(int i = 1 ; i <= N ; i++ ) { if( color[i] != -1 ) continue ; ans = (ans << 1 ) % MOD ; vector<int> fila(1,i) ; color[i] = 0 ; int ini = 0 ; while( ini < sz(fila) ) { int x = fila[ini++] ; walk(1,1,2*N, x , fila ) ; } sort(all(fila), [&](int a, int b ) { return L[a] < L[b] ; } ) ; set<int> group[2] ; for(auto e : fila ) { auto it = group[ color[e] ].upper_bound(R[e]) ; if( it != group[ color[e] ].begin() ) { it-- ; if( *it > L[e] ) { printf("0\n") ; return 0 ; } } group[ color[e] ].insert(R[e] ) ; } } printf("%d\n", ans ) ; }

Compilation message (stderr)

port_facility.cpp: In function 'int main()':
port_facility.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |  scanf("%d", &N ) ;
      |  ~~~~~^~~~~~~~~~~
port_facility.cpp:75:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |  for(int i=1 ; i <= N ; i++ ) scanf("%d %d", &L[i] , &R[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...