제출 #107340

#제출 시각아이디문제언어결과실행 시간메모리
107340popovicirobertPort Facility (JOI17_port_facility)C++14
100 / 100
5157 ms209040 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long // 217 // 44 using namespace std; const int MOD = (int) 1e9 + 7; const int INF = (int) 1e9; const int MAXN = (int) 1e6; inline void mod(int &x) { if(x >= MOD) x -= MOD; } struct SegTree { int aint[8 * MAXN + 1]; int n; inline void init(int _n) { n = _n; for(int i = 1; i <= 4 * n; i++) { aint[i] = -INF; } } void update(int nod, int left, int right, int pos, int cur) { if(left == right) { aint[nod] = cur; } else { int mid = (left + right) / 2; if(pos <= mid) update(2 * nod, left, mid, pos, cur); else update(2 * nod + 1, mid + 1, right, pos, cur); aint[nod] = max(aint[2 * nod], aint[2 * nod + 1]); } } int query(int nod, int left, int right, int l, int r) { if(l <= left && right <= r) { return aint[nod]; } else { int mid = (left + right) / 2; int ans = -INF; if(l <= mid) ans = max(ans, query(2 * nod, left, mid, l, r)); if(mid < r) ans = max(ans, query(2 * nod + 1, mid + 1, right, l, r)); return ans; } } void update(int pos, int cur) { update(1, 1, n, pos, cur); } int query(int l, int r) { return query(1, 1, n, l, r); } }; SegTree stl, str; pair <int, int> arr[MAXN + 1]; int who[2 * MAXN + 1]; bool vis[MAXN + 1], col[MAXN + 1]; int n; void dfs(int nod, int c) { col[nod] = c; vis[nod] = 1; while(1) { int cur = str.query(arr[nod].first, arr[nod].second); if(cur <= arr[nod].second) { break; } int id = who[cur]; str.update(arr[id].first, -INF); if(vis[id] == 0) { dfs(id, c ^ 1); } } while(1) { int cur = -stl.query(arr[nod].first, arr[nod].second); if(cur >= arr[nod].first) { break; } int id = who[cur]; stl.update(arr[id].second, -INF); if(vis[id] == 0) { dfs(id, c ^ 1); } } } struct Fenwick { int aib[2 * MAXN + 1]; int n; inline void init(int _n) { n = _n; for(int i = 1; i <= n; i++) { aib[i] = 0; } } inline void update(int pos) { for(int i = pos; i <= n; i += lsb(i)) { aib[i]++; } } inline int query(int pos) { int ans = 0; for(int i = pos; i > 0; i -= lsb(i)) { ans += aib[i]; } return ans; } inline int sum(int l, int r) { return query(r) - query(l - 1); } }; const int MAXBUF = (1 << 17); char buf[MAXBUF]; int pbuf = MAXBUF; inline char nextch() { if(pbuf == MAXBUF) { fread(buf, 1, MAXBUF, stdin); pbuf = 0; } return buf[pbuf++]; } inline int getnr() { char ch = nextch(); while(!isdigit(ch)) { ch = nextch(); } int nr = 0; while(isdigit(ch)) { nr = nr * 10 + ch - '0'; ch = nextch(); } return nr; } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i; //ios::sync_with_stdio(false); //cin.tie(0), cout.tie(0); n = getnr(); stl.init(2 * n), str.init(2 * n); for(i = 1; i <= n; i++) { arr[i].first = getnr(); arr[i].second = getnr(); str.update(arr[i].first, arr[i].second); stl.update(arr[i].second, -arr[i].first); who[arr[i].first] = who[arr[i].second] = i; } int ans = 1; for(i = 1; i <= n; i++) { if(vis[i] == 0) { dfs(i, 0); ans *= 2; mod(ans); } } Fenwick fen[2]; for(i = 0; i < 2; i++) { fen[i].init(2 * n); } vector <int> ord(n + 1); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](const int &a, const int &b) { return arr[a].first < arr[b].first; }); for(i = 1; i <= n; i++) { int id = ord[i]; if(fen[col[id]].sum(arr[id].first, arr[id].second) > 0) { ans = 0; break; } fen[col[id]].update(arr[id].second); } cout << ans; //cin.close(); //cout.close(); return 0; }

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

port_facility.cpp: In function 'char nextch()':
port_facility.cpp:162:14: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         fread(buf, 1, MAXBUF, stdin);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...