이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,ll> pii;
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 4e6;
const ll A = 911382323;
const ll B = 972663749;
ll modpow(ll x, ll n){
if(n == 0) return 1%mod;
ll u = modpow(x, n/2);
u = (u * u) % mod;
if(n % 2) u = (u * x) % mod;
return u;
}
ll inverse(ll x){
return modpow(x, mod-2);
}
ll add(ll ans, ll val){
ans = (ans + val) % mod;
return ans;
}
ll mul(ll ans, ll val){
ans = (ans * val) % mod;
return ans;
}
ll sub(ll ans, ll val){
ans = (ans - val) % mod;
if(ans < 0) ans += mod;
return ans;
}
ll _div(ll ans, ll val){
ans = (ans * inverse(val)) % mod;
return ans;
}
ll fakt[mxn];
ll bc(ll n, ll k){
return (fakt[n]*inverse((fakt[k]*fakt[n-k])%mod))%mod;
}
ll sq(ll x){
return x*x;
}
ll rsum(ll a, ll b){
return (b-a+1)*(a+b)/2;
}
void prec(){
fakt[0] = 1;
fr(i, 1, mxn){
fakt[i] = mul(fakt[i-1], i);
}
}
int a[mxn], b[mxn];
vector<int> g[mxn];
bool vis[mxn];
void dfs(int u){
vis[u] = true;
for(auto e : g[u]) if(!vis[e]) dfs(e);
}
void solve(){
int n;
cin >> n;
int val[2*n+1];
memset(val, 0, sizeof(val));
int id[2*n+1];
fr(i, 0, n){
cin >> a[i] >> b[i];
val[a[i]] = +1;
val[b[i]] = -1;
id[a[i]] = id[b[i]] = i;
}
set<int> S;
fr(i, 1, 2*n+1){
if(val[i] == 0) continue;
if(val[i] > 0){
S.insert(-i);
}
else{
int c =id[i];
int l = a[c];
S.erase(-l);
for(auto u : S){
if(-u > l){
g[c].pb(id[-u]);
g[id[-u]].pb(c);
}
}
}
}
ll ans = 1;
fr(i, 0, n){
if(vis[i]) continue;
dfs(i);
ans = mul(ans, 2);
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |