제출 #120433

#제출 시각아이디문제언어결과실행 시간메모리
120433tinderPort Facility (JOI17_port_facility)C++14
78 / 100
6141 ms977892 KiB
#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; #define x first #define id second using info = pair<int, int>; const int maxn = 2e6 + 6; const int mod = 1e9 + 7; int n, s[maxn], t[maxn]; namespace graph { vector<int> g[maxn], w[maxn]; void add_edge(int u, int v, int col) { w[u].emplace_back(col); w[v].emplace_back(col); g[u].emplace_back(v); g[v].emplace_back(u); } } using namespace graph; namespace merge_sort_tree { vector<info> ft[maxn << 2]; int ptr[maxn << 2]; int i, j, k, id; info data; // insert(t, {s, id}) void insert(int u = 1, int l = 1, int r = 2 * n) { ft[u].emplace_back(data); if(l == r) return; int m = l + r >> 1; if(i <= m) insert(u << 1, l, m); else insert(u << 1 | 1, m + 1, r); } void insert(int _i, info _data) { i = _i, data = _data; insert(); } // update on range [l, r] => over elems leq k: update(l, r, k, id) void update(int u = 1, int l = 1, int r = 2 * n) { if(r < i or l > j or i > j) return; if(i <= l and r <= j) { while(ptr[u] < ft[u].size() and ft[u][ptr[u]].x <= k) ptr[u]++; if(ptr[u] and ft[u].size()) add_edge(id, ft[u][0].id, 1); return; } int m = l + r >> 1; update(u << 1, l, m); update(u << 1 | 1, m + 1, r); } void update(int _i, int _j, int _k, int _id) { i = _i, j = _j, k = _k, id = _id; update(); } // add n lg n edges calculated by update () void build(int u = 1, int l = 1, int r = 2 * n) { for(int j = 1; j < ptr[u]; j++) { add_edge(ft[u][j - 1].id, ft[u][j].id, 0); } if(l == r) return; int m = l + r >> 1; build(u << 1, l, m); build(u << 1 | 1, m + 1, r); } } using namespace merge_sort_tree; int vis[maxn]; int col[maxn]; void dfs(int u) { vis[u] = 1; for(int i = 0; i < g[u].size(); i++) { int v = g[u][i], c = w[u][i]; if(!vis[v]) { col[v] = col[u] ^ c; dfs(v); } } } bool valid() { vector<int> id(2 * n + 5), op(2 * n + 5); for(int i = 1; i <= n; i++) { id[s[i]] = i, op[s[i]] = +1; id[t[i]] = i, op[t[i]] = -1; } vector<int> A, B; for(int i = 1; i <= (2 * n); i++) { if(op[i] == +1) { col[id[i]] ? A.push_back(id[i]) : B.push_back(id[i]); } else { vector<int> &w0t = col[id[i]] ? A : B; if(w0t.empty() or w0t.back() != id[i]) { return false; } else { w0t.pop_back(); } } } return true; } int main(int argc, char const *argv[]) { scanf("%d", &n); vector<ii> tmp; for(int i = 1; i <= n; i++) { scanf("%d %d", &s[i], &t[i]); tmp.emplace_back(s[i], t[i]); } sort(tmp.begin(), tmp.end()); for(int i = 0; i < n; i++) { s[i + 1] = tmp[i].first; t[i + 1] = tmp[i].second; } for(int i = 1; i <= n; i++) { insert(t[i], {s[i], i}); } for(int i = 1; i <= n; i++) { update(s[i] + 1, t[i] - 1, s[i] - 1, i); } build(); int ans = 1; for(int i = 1; i <= n; i++) { if(!vis[i]) { ans <<= 1; if(ans >= mod) { ans -= mod; } dfs(i); } } if(valid()) { printf("%d\n", ans); } else { puts("0"); } return 0; }

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

port_facility.cpp: In function 'void merge_sort_tree::insert(int, int, int)':
port_facility.cpp:35:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r >> 1;
           ~~^~~
port_facility.cpp: In function 'void merge_sort_tree::update(int, int, int)':
port_facility.cpp:47:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(ptr[u] < ft[u].size() and ft[u][ptr[u]].x <= k) ptr[u]++;
          ~~~~~~~^~~~~~~~~~~~~~
port_facility.cpp:50:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   } int m = l + r >> 1;
             ~~^~~
port_facility.cpp: In function 'void merge_sort_tree::build(int, int, int)':
port_facility.cpp:63:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r >> 1;
           ~~^~~
port_facility.cpp: In function 'void dfs(int)':
port_facility.cpp:74:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g[u].size(); i++) {
                 ~~^~~~~~~~~~~~~
port_facility.cpp: In function 'int main(int, const char**)':
port_facility.cpp:106:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
port_facility.cpp:109:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &s[i], &t[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...