結果
問題 | No.274 The Wall |
ユーザー | kei |
提出日時 | 2018-10-02 23:51:48 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,112 bytes |
コンパイル時間 | 1,763 ms |
コンパイル使用メモリ | 172,592 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-12 10:07:20 |
合計ジャッジ時間 | 2,814 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 3 ms
5,248 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
ソースコード
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; } template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; } template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; } /* <url:https://yukicoder.me/problems/no/274> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ struct BIT { int N; vector<ll> bit1; vector<ll> bit2; BIT(ll N):N(N) { /* BITは[1..N]で扱う */ bit1.resize(N + 1, 0); bit2.resize(N + 1, 0); } void add1(int x, ll val){ while (x <= N) { bit1[x] += val; x += x & -x; } } void add2(int x, ll val){ while (x <= N) { bit2[x] += val; x += x & -x; } } // [l,r] void RangeAdd(int l,int r,ll val){ // Update BIT1 add1(l,val); add1(r+1,-val); // Update BIT2 add2(l,val*(l-1)); add2(r+1,-val*r); } ll sum1(int x){ ll ret = 0; while (x) { ret += bit1[x]; x &= (x - 1); } return (ret); } ll sum2(int x){ ll ret = 0; while (x) { ret += bit2[x]; x &= (x - 1); } return (ret); } ll sum(int x){ return sum1(x)*x - sum2(x); } // [l,r] ll RangeSum(int l,int r){ return sum(r) - sum(l-1); } }; string solve(){ int N,M; cin >> N >> M; BIT bit(M+1); for(int i = 0; i < N;i++){ int L,R; cin >> L >> R; L++; R++; int L2 = M+1-R,R2 = M+1-L; int LL,LR,RL,RR; if(L <= L2){ LL = L; LR = R; RL = L2; RR = R2; }else{ LL = L2; LR = R2; RL = L; RR = R; } if(bit.RangeSum(LL, LR)==0){ bit.RangeAdd(LL,LR,1); }else{ if(bit.RangeSum(RL,RR)==0){ bit.RangeAdd(RL,RR,1); }else{ return "NO"; } } } return "YES"; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); cout << solve() << endl; return 0; }