제출 #292854

#제출 시각아이디문제언어결과실행 시간메모리
292854BTheroPort Facility (JOI17_port_facility)C++17
10 / 100
69 ms94456 KiB
// 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)1e6 + 5; const int MOD = (int)1e9 + 7; int addMod(int a, int b, int m = MOD) { a += b; if (m <= a) { a -= m; } return a; } int mulMod(int a, int b, int m = MOD) { return a * 1ll * b % m; } vector<int> t[MAXN << 2]; pii arr[MAXN]; int n; namespace DSU { int par[MAXN], sz[MAXN], up[MAXN]; void init(int n) { for (int i = 1; i <= n; ++i) { par[i] = i; sz[i] = 1; up[i] = 0; } } int get(int x, int &col) { while (x != par[x]) { col ^= up[x]; x = par[x]; } return x; } bool uni(int a, int b) { int path = 0; int na = get(a, path); int nb = get(b, path); if (na == nb) { return path == 1; } if (sz[na] < sz[nb]) { swap(a, b); swap(na, nb); } sz[na] += sz[nb]; par[nb] = na; up[nb] = 1 - path; return 1; } int ans() { int ret = 1; for (int i = 1; i <= n; ++i) { if (par[i] == i) { ret = addMod(ret, ret); } } return ret; } }; bool cmp(pii a, pii b) { return a.se < b.se; } void update(int v, int tl, int tr, int l, int r, int id) { if (l > r || tl > r || tr < l) { return; } if (l <= tl && tr <= r) { t[v].pb(id); return; } int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); update(c1, tl, mid, l, r, id); update(c2, mid + 1, tr, l, r, id); } void go(int v, int tl, int tr, int p, int id) { int sz = (int)t[v].size(); for (int i = 0; i < 5 && i < sz; ++i) { if (!DSU::uni(t[v][sz - i - 1], id)) { printf("0\n"); exit(0); } } if (tl != tr) { int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); if (p <= mid) { go(c1, tl, mid, p, id); } else { go(c2, mid + 1, tr, p, id); } } } 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); DSU::init(n); for (int i = 1; i <= n; ++i) { go(1, 1, 2 * n, arr[i].fi, i); update(1, 1, 2 * n, arr[i].fi + 1, arr[i].se - 1, i); } printf("%d\n", DSU::ans()); } int main() { int tt = 1; while (tt--) { solve(); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

port_facility.cpp: In function 'void solve()':
port_facility.cpp:136:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  136 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
port_facility.cpp:139:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  139 |     scanf("%d %d", &arr[i].fi, &arr[i].se);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...