이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = (int)2e5 + 5;
const int MOD = (int)1e9 + 7;
set<pii> t[MAXN << 2];
int col[MAXN];
pii arr[MAXN];
int n;
bool cmp(pii a, pii b) {
return a.se < b.se;
}
void add(int v, int tl, int tr, int l, int r, int id) {
t[v].insert(mp(r, id));
if (tl == tr) {
return;
}
int mid = (tl + tr) >> 1;
int c1 = (v << 1), c2 = (c1 | 1);
if (l <= mid) {
add(c1, tl, mid, l, r, id);
}
else {
add(c2, mid + 1, tr, l, r, id);
}
}
void go(int v, int tl, int tr, int l, int r, int L, int R, vector<int> &e) {
if (l > r || tl > r || tr < l) {
return;
}
if (l <= tl && tr <= r) {
auto it = t[v].lower_bound(mp(L, 0));
while (it != t[v].end() && it -> fi <= R) {
e.pb(it -> se);
it = t[v].erase(it);
}
return;
}
int mid = (tl + tr) >> 1;
int c1 = (v << 1), c2 = (c1 | 1);
go(c1, tl, mid, l, r, L, R, e);
go(c2, mid + 1, tr, l, r, L, R, e);
}
void dfs(int v) {
vector<int> e;
go(1, 1, 2 * n, 1, arr[v].fi - 1, arr[v].fi + 1, arr[v].se - 1, e);
go(1, 1, 2 * n, arr[v].fi + 1, arr[v].se - 1, arr[v].se + 1, 2 * n, e);
for (int to : e) {
if (col[to] == -1) {
col[to] = 1 - col[v];
dfs(to);
}
else if (col[to] == col[v]) {
printf("0\n");
exit(0);
}
}
}
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d %d", &arr[i].fi, &arr[i].se);
}
sort(arr + 1, arr + n + 1, cmp);
for (int i = 1; i <= n; ++i) {
add(1, 1, 2 * n, arr[i].fi, arr[i].se, i);
}
fill(col + 1, col + n + 1, -1);
int ans = 1;
for (int i = 1; i <= n; ++i) {
if (col[i] == -1) {
col[i] = 0;
dfs(i);
ans = (ans * 2) % MOD;
}
}
printf("%d\n", ans);
}
int main() {
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
port_facility.cpp: In function 'void solve()':
port_facility.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
88 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
port_facility.cpp:91:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
91 | scanf("%d %d", &arr[i].fi, &arr[i].se);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |