Submission #313032

#TimeUsernameProblemLanguageResultExecution timeMemory
313032ttnhuy313Port Facility (JOI17_port_facility)C++14
100 / 100
2713 ms167724 KiB
#include <bits/stdc++.h> using namespace std; const int mxN=1e6, M=1e9+7; int n, a[mxN], b[mxN], c[mxN], d[2*mxN], ans=1, st[2][mxN], sth[2]; struct segtree { array<int, 2> a[4*mxN]; void bld() { for(int i=2*n-1; i; --i) a[i]=max(a[2*i], a[2*i+1]); } void upd(int i, array<int, 2> x) { for(a[i+=2*n]=x; i/=2; ) a[i]=max(a[2*i], a[2*i+1]); } array<int, 2> qry(int l, int r) { array<int, 2> b={INT_MIN, -1}; for(l+=2*n, r+=2*n; l<r; ++l/=2, r/=2) { if(l&1) b=max(a[l], b); if(r&1) b=max(a[r-1], b); } return b; } } st1, st2; void dfs(int u) { st1.upd(a[u], {-1, -1}); st2.upd(b[u], {-2*n, -1}); array<int, 2> v; while((v=st1.qry(a[u], b[u]))[1]!=-1) { if(v[0]<b[u]) break; c[v[1]]=c[u]^1; dfs(v[1]); } while((v=st2.qry(a[u], b[u]))[1]!=-1) { if(-v[0]>a[u]) break; c[v[1]]=c[u]^1; dfs(v[1]); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i=2*n; i<4*n; ++i) { st1.a[i]={-1, -1}; st2.a[i]={-2*n, -1}; } for(int i=0; i<n; ++i) { cin >> a[i] >> b[i], --a[i], --b[i]; st1.a[a[i]+2*n]={b[i], i}; st2.a[b[i]+2*n]={-a[i], i}; } st1.bld(); st2.bld(); memset(c, -1, 4*n); for(int i=0; i<n; ++i) { if(c[i]==-1) { c[i]=0; dfs(i); ans=ans*2%M; } } memset(d, -1, 4*2*n); for(int i=0; i<n; ++i) d[a[i]]=d[b[i]]=i; for(int i=0; i<2*n; ++i) { if(sth[c[d[i]]]&&st[c[d[i]]][sth[c[d[i]]]-1]==d[i]) --sth[c[d[i]]]; else st[c[d[i]]][sth[c[d[i]]]++]=d[i]; } cout << (!sth[0]&&!sth[1]?ans:0); }

Compilation message (stderr)

In file included from /usr/include/string.h:635,
                 from /usr/include/c++/9/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:48,
                 from port_facility.cpp:2:
In function 'void* memset(void*, int, size_t)',
    inlined from 'int main()' at port_facility.cpp:72:8:
/usr/include/x86_64-linux-gnu/bits/string3.h:90:33: warning: 'void* __builtin___memset_chk(void*, int, long unsigned int, long unsigned int)' specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
   90 |   return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...