제출 #427108

#제출 시각아이디문제언어결과실행 시간메모리
427108oolimryPort Facility (JOI17_port_facility)C++17
0 / 100
140 ms220900 KiB
#include <bits/stdc++.h> using namespace std; #define sz(x) (int) (x).size() #define all(x) (x).begin(), (x).end() #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl; #define tern(cond, a, b) (cond ? a : b) #define l first #define r second typedef long long lint; typedef pair<int,int> ii; const lint mod = 1000000007; int p[2000005]; int ans; int findSet(int u){ if(p[u] == u) return u; else return p[u] = findSet(p[u]); } inline bool unionSet(int u, int v){ u = findSet(u), v = findSet(v); if(u == v) return false; if(rand()&1) swap(u,v); p[u] = v; ans--; return true; } ii arr[100005]; const int N = 1<<21; map<int,int> tree[2*N]; inline map<int,int> merge(map<int,int> A, map<int,int> B){ if(sz(A) > sz(B)) swap(A,B); for(ii x : A) B[x.first] += x.second; return B; } inline void update(int u, int h, int v){ int i = arr[u].r + N; for(;i > 0;i >>= 1){ auto it = tree[i].find(h); if(it == tree[i].end()) tree[i][h] = v; else if(it->second == 1 and v == -1) tree[i].erase(it); else it->second += v; } } inline map<int,int> query(int l, int r){ map<int,int> res; for(l += N, r += N;l < r;l >>= 1, r >>= 1){ if(l&1) res = merge(res, tree[l++]); if(r&1) res = merge(res, tree[--r]); } return res; } vector<int> belongsto[1000005]; inline void combine(int a, int b){ ///pushes a's stuff to b show2(a,b); vector<int> &A = belongsto[a]; vector<int> &B = belongsto[b]; if(sz(A) > sz(B)) swap(A,B); for(int x : A) B.push_back(x); A.clear(); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; ans = n; for(int i = 0;i < n;i++) cin >> arr[i].l >> arr[i].r; sort(arr,arr+n); for(int i = 0;i < n;i++){ p[i] = i; belongsto[i].push_back(i); } for(int u = 0;u < n;u++){ vector<int> stuffs = {u}; auto M = query(arr[u].l, arr[u].r); for(ii x : M) stuffs.push_back(x.first); for(int i = 1;i < sz(stuffs);i++) unionSet(stuffs[i-1], stuffs[i]); int newhead = findSet(u); update(u, u, 1); for(int h : stuffs){ //cerr << h << " "; if(h == newhead) continue; for(int x : belongsto[h]){ update(x, h, -1); update(x, newhead, 1); } combine(h, newhead); } //cerr << endl; } lint actlans = 1; for(int i = 0;i < ans;i++){ actlans *= 2; if(actlans >= mod) actlans -= mod; } cout << actlans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...