제출 #543615

#제출 시각아이디문제언어결과실행 시간메모리
543615PixelCatPort Facility (JOI17_port_facility)C++14
100 / 100
4629 ms300844 KiB
/* code by the cute ~~Dengdualang~~ PixelCat owo */ /* as cute as nacho neko (aka. my wife)! */ /* Nhade stay for a night here */ /* 183234 deng deng deng pixelcat oops */ /* (yang wang yesu)*2 */ /* ^ some weird stuff. nvm =w= */ // #pragma GCC optimize("O4,unroll-loops,no-stack-protector") // #pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma") #include <bits/stdc++.h> #pragma pack(0) #define int LL //__int128 #define double long double using namespace std; using LL = long long; using LLL = __int128_t; using uLL = unsigned long long; using pii = pair<int, int>; #define For(i, a, b) for (int i = a; i <= b; i++) #define Fors(i, a, b, s) for (int i = a; i <= b; i += s) #define Forr(i, a, b) for (int i = a; i >= b; i--) #define F first #define S second #define L(id) (id * 2 + 1) #define R(id) (id * 2 + 2) #define LO(x) (x & (-x)) #define eb emplace_back #define all(x) x.begin(), x.end() #define sz(x) ((int)x.size()) #define mkp make_pair // #define MOD (int)(998244353) #define MOD (int)((LL)1'000'000'007) #define INF (int)(4e18) // #define INF 1e9 #define EPS (1e-6) #ifdef NYAOWO #include "library/debug.hpp" inline void USACO(const string &s) { cerr << "USACO: " << s << "\n"; } #else #define debug(...) inline void timer() {} inline void USACO(const string &s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } #endif inline void NYA() { ios::sync_with_stdio(false); cin.tie(0); } inline int gcd(int a, int b) { return __gcd(a, b); } inline int lcm(int a, int b) { return a / gcd(a, b) * b; } int fpow(int b, int p, const int &mod) { int ans = 1; while (p) { if (p & 1) ans = ans * b % mod; p >>= 1; b = b * b % mod; } return ans; } int fpow(int b, int p) { return fpow(b, p, MOD); } template <typename T> inline void chmin(T &_a, const T &_b) { if (_b < _a) _a = _b; } template <typename T> inline void chmax(T &_a, const T &_b) { if (_b > _a) _a = _b; } // mt19937_64 rng( // chrono::steady_clock::now().time_since_epoch().count()); struct DSU{ int p[1000010]; char d[1000010]; bool ok=true; int find(int x){ if(!p[x]) return x; int a=find(p[x]); d[x]^=d[p[x]]; p[x]=a; return a; } void uni(int a,int b,int c){ // debug(a,b,c); if(!a || !b) return; int x=find(a); int y=find(b); int di=d[a]^d[b]; if(x==y){ ok=ok && (di==c); }else{ p[x]=y; d[x]=(di^c); } } }dsu; pii p[1000010]; struct SegTree{ vector<int32_t> v[4000040]; int32_t ptr[4000040]; int32_t mx[4000040]; int32_t mn[4000040]; void build(int id,int l,int r){ ptr[id]=0; For(i,l,r) v[id].eb(i); sort(all(v[id]),[&](int a,int b){ return p[a].F<p[b].F; }); mx[id]=p[r].S; mn[id]=p[l].S; // debug(id,l,r,v[id],mx[id],mn[id]); // vector<pii> v2; // for(auto &i:v[id]) v2.eb(p[i]); // debug(v2); if(l==r) return; int m=(l+r)/2; build(L(id),l,m); build(R(id),m+1,r); } int add(int id,int l,int r,int L,int R,int tar,int last){ // debug(id,l,r,L,R,tar,last); if(mn[id]>=R || mx[id]<=L) return last; if(mn[id]>=L && mx[id]<=R){ if(p[v[id][0]].F>=L) return last; dsu.uni(last,v[id][0],0); dsu.uni(tar,v[id][0],1); // debug("oao?"); while(ptr[id]<sz(v[id]) && p[v[id][ptr[id]]].F<L){ if(ptr[id]) dsu.uni(v[id][ptr[id]-1],v[id][ptr[id]],0); // debug(ptr[id],v[id][ptr[id]],p[v[id][ptr[id]]]); ptr[id]++; } // debug("owo"); return v[id][0]; } int m=(l+r)/2; last=add(L(id),l,m,L,R,tar,last); last=add(R(id),m+1,r,L,R,tar,last); return last; } }seg; int32_t main() { NYA(); // nyaacho >/////< // miku sama bless me >/////< int n; cin>>n; vector<int> pa(n); For(i,1,n){ cin>>p[i].F>>p[i].S; pa[i-1]=i; } sort(p+1,p+n+1,[](auto &a,auto &b){ return a.S<b.S; }); sort(all(pa),[](auto &a,auto &b){ return p[a].F<p[b].F; }); seg.build(0,1,n); for(auto &i:pa){ seg.add(0,1,n,p[i].F,p[i].S,i,0); } // debug("owo"); if(!dsu.ok){ cout<<"0\n"; return 0; } int ans=1; For(i,1,n){ int r=dsu.find(i); if(r!=n+1){ dsu.uni(r,n+1,0); ans+=ans; if(ans>=MOD) ans-=MOD; } } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...