結果
問題 | No.274 The Wall |
ユーザー | SHIJOU |
提出日時 | 2020-09-12 04:08:59 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 6,141 bytes |
コンパイル時間 | 2,985 ms |
コンパイル使用メモリ | 230,196 KB |
実行使用メモリ | 28,780 KB |
最終ジャッジ日時 | 2024-06-09 12:09:29 |
合計ジャッジ時間 | 6,576 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
10,752 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
ソースコード
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = int64_t; using ld = long double; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;} struct SCC { struct csr { vector<int> start, elist; csr(int n, const vector<pair<int, int>> &edges) : start(n+1), elist(edges.size()) { for(pair<int, int> e:edges) { start[e.first+1]++; } for(int i = 1; i <= n; i++) { start[i] += start[i-1]; } vector<int> counter = start; for(pair<int, int> e:edges) { elist[counter[e.first]++] = e.second; } } }; int n; vector<pair<int, int>> edges; SCC(int n_) : n(n_) {} void add(int from, int to) {edges.emplace_back(from, to);} pair<int, vector<int>> scc_ids() { csr g(n, edges); int now_ord = 0, group_num = 0; vector<int> used, low(n), ord(n, -1), ids(n); used.reserve(n); auto dfs = [&](auto self, int v)->void { low[v] = ord[v] = now_ord++; used.push_back(v); for(int i = g.start[v]; i < g.start[v+1]; i++) { int to = g.elist[i]; if(ord[to] == -1) { self(self, to); low[v] = min(low[v], low[to]); } else { low[v] = min(low[v], ord[to]); } } if(low[v] == ord[v]) { while(true) { int u = used.back(); used.pop_back(); ord[u] = n; ids[u] = group_num; if(u == v) break; } group_num++; } }; for(int i = 0; i < n; i++) { if(ord[i] == -1) dfs(dfs, i); } for(int &x:ids) { x = group_num - 1 - x; } return {group_num, ids}; } vector<vector<int>> scc() { pair<int, vector<int>> ids = scc_ids(); int group_num = ids.first; vector<int> counts(group_num); for(int x:ids.second) counts[x]++; vector<vector<int>> groups(group_num); for(int i = 0; i < group_num; i++) { groups[i].reserve(counts[i]); } for(int i = 0; i < n; i++) { groups[ids.second[i]].push_back(i); } return groups; } }; //SCC is needed struct two_sat { int n; vector<bool> boolean_val; SCC scc; two_sat():n(0), scc(0) {} two_sat(int n_):n(n_), boolean_val(n_), scc(n_<<1) {} void add(int i, bool ii, int j, bool jj) { scc.add(i + (ii?0:n), j + (jj?n:0)); scc.add(j + (jj?0:n), i + (ii?n:0)); } bool satisfiable() { vector<int> id = scc.scc_ids().second; for(int i = 0; i < n; i++) { if(id[i] == id[i+n]) return false; boolean_val[i] = id[i] < id[i+n]; } return true; } }; template <class S, class F> struct SegTreeL { using FX = function<S(S, S)>; using FA = function<S(S, F)>; using FF = function<F(F, F)>; int n; FX fx; FA fa; FF ff; const S es; const F ef; vector<S> dat; vector<F> laz; SegTreeL(int n_, FX fx_, FA fa_, FF ff_, S es_, F ef_) : fx(fx_), fa(fa_), ff(ff_), es(es_), ef(ef_) { n = 1; while(n_ > n) n <<= 1; dat.assign(n*2-1, es); laz.assign(n*2-1, ef); } inline int chld(int k) {return k*2+1;} inline int chrd(int k) {return k*2+2;} void set(int i, S s) {dat[i+n-1] = s;} void build() { for(int k = n-2; k >= 0; k--) dat[k] = fx(dat[chld(k)], dat[chrd(k)]); } void eval(int k) { if(laz[k] == ef) return; if(k < n-1) { laz[chld(k)] = ff(laz[chld(k)], laz[k]); laz[chrd(k)] = ff(laz[chrd(k)], laz[k]); } dat[k] = fa(dat[k], laz[k]); laz[k] = ef; } void update(int a, int b, F x, int k, int l, int r) { eval(k); if(a <= l and r <= b) { laz[k] = ff(laz[k], x); eval(k); } else if(a < r and l < b) { update(a, b, x, chld(k), l, (l+r)>>1); update(a, b, x, chrd(k), (l+r)>>1, r); dat[k] = fx(dat[chld(k)], dat[chrd(k)]); } } void update(int a, int b, F x) {update(a, b, x, 0, 0, n);} S query(int a, int b, int k, int l, int r) { eval(k); if(r <= a or b <= l) return es; else if(a <= l and r <= b) return dat[k]; else { S vl = query(a, b, chld(k), l, (l+r)>>1); S vr = query(a, b, chrd(k), (l+r)>>1, r); return fx(vl, vr); } } S query(int a, int b) {return query(a, b, 0, 0, n);} //debug inline const S operator[](const int i) {return query(i, i+1);} void print() {for(int i = 0; i < n; i++) cout << (*this)[i] << (i == n-1?'\n':' ');} }; #define M 4010 //head int n, m; vi pink[M]; bitset<M/2> check; auto fx = [](set<int> a, set<int> b)->set<int> { set<int> res; set_union(a.begin(), a.end(), b.begin(), b.end(), inserter(res, res.end())); return res; }; SegTreeL<set<int>, set<int>> rng(M>>1, fx, fx, fx, set<int>(), set<int>()); int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; two_sat TS(n); rep(i, n) { check = 0; int l, r; cin >> l >> r; set<int> u = rng.query(l, r+1); for(int x:u) { if(x >= n) { TS.add(i, false, x-n, true); } else { TS.add(i, false, x, false); } } u = rng.query(m-1-r, m-l); for(int x:u) { if(x >= n) { TS.add(i, true, x-n, true); } else { TS.add(i, true, x, false); } } rng.update(l, r+1, set<int>({i})); rng.update(m-1-r, m-l, set<int>({i+n})); } cout << (TS.satisfiable()?"YES\n":"NO\n"); }