제출 #293035

#제출 시각아이디문제언어결과실행 시간메모리
293035BTheroPort Facility (JOI17_port_facility)C++17
컴파일 에러
0 ms0 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)1200005; const int MOD = (int)1e9 + 7; vector<pii> lt[MAXN * 4], rt[MAXN * 4]; int col[MAXN]; pii arr[MAXN]; int n; bool cmp(pii a, pii b) { return a.se < b.se; } void addL(int v, int tl, int tr, int l, int r, int id) { if (tl == tr) { lt[v].pb(mp(r, id)); return; } int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); if (l <= mid) { addL(c1, tl, mid, l, r, id); } else { addL(c2, mid + 1, tr, l, r, id); } } void addR(int v, int tl, int tr, int l, int r, int id) { if (tl == tr) { rt[v].pb(mp(l, id)); return; } int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); if (r <= mid) { addR(c1, tl, mid, l, r, id); } else { addR(c2, mid + 1, tr, l, r, id); } } void prep(int v, int tl, int tr) { if (tl != tr) { int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); prep(c1, tl, mid); prep(c2, mid + 1, tr); lt[v].resize(lt[c1].size() + lt[c2].size()); rt[v].resize(rt[c1].size() + rt[c2].size()); merge(all(lt[c1]), all(lt[c2]), lt[v].begin()); merge(all(rt[c1]), all(rt[c2]), rt[v].begin()); } } void prep2(int v, int tl, int tr) { reverse(all(rt[v])); if (tl != tr) { int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); prep2(c1, tl, mid); prep2(c2, mid + 1, tr); } } void go(int v, int tl, int tr, int l, int r, int limL, int limR, vector<int> &e) { if (l > r || tl > r || tr < l) { return; } if (l <= tl && tr <= r) { while (!lt[v].empty() && lt[v].back().fi >= limL) { e.pb(lt[v].back().se); lt[v].pop_back(); } while (!rt[v].empty() && rt[v].back().fi <= lim) { e.pb(rt[v].back().se); rt[v].pop_back(); } return; } int mid = (tl + tr) >> 1; int c1 = (v << 1), c2 = (c1 | 1); go(c1, tl, mid, l, r, limL, limR, e); go(c2, mid + 1, tr, l, r, limL, limR, e); } void dfs(int v) { vector<int> e; go(1, 1, 2 * n, arr[v].fi + 1, arr[v].se - 1, arr[v].se + 1, arr[v].fi - 1, 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) { addL(1, 1, 2 * n, arr[i].fi, arr[i].se, i); addR(1, 1, 2 * n, arr[i].fi, arr[i].se, i); } prep(1, 1, 2 * n); prep2(1, 1, 2 * n); 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 go(int, int, int, int, int, int, int, std::vector<int>&)':
port_facility.cpp:98:49: error: 'lim' was not declared in this scope; did you mean 'limL'?
   98 |     while (!rt[v].empty() && rt[v].back().fi <= lim) {
      |                                                 ^~~
      |                                                 limL
port_facility.cpp: In function 'void solve()':
port_facility.cpp:129:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  129 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
port_facility.cpp:132:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  132 |     scanf("%d %d", &arr[i].fi, &arr[i].se);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~