結果

問題 No.1290 Addition and Subtraction Operation
ユーザー beetbeet
提出日時 2020-11-13 22:17:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 1,652 bytes
コンパイル時間 4,262 ms
コンパイル使用メモリ 233,612 KB
実行使用メモリ 10,856 KB
最終ジャッジ日時 2023-09-30 03:10:38
合計ジャッジ時間 13,097 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 20 ms
5,104 KB
testcase_43 AC 20 ms
5,204 KB
testcase_44 AC 20 ms
5,040 KB
testcase_45 AC 20 ms
5,068 KB
testcase_46 AC 20 ms
5,172 KB
testcase_47 AC 20 ms
5,044 KB
testcase_48 AC 20 ms
5,000 KB
testcase_49 AC 20 ms
5,040 KB
testcase_50 AC 20 ms
5,044 KB
testcase_51 AC 20 ms
5,100 KB
testcase_52 AC 20 ms
4,956 KB
testcase_53 AC 20 ms
5,156 KB
testcase_54 AC 20 ms
5,068 KB
testcase_55 AC 20 ms
5,068 KB
testcase_56 AC 20 ms
5,040 KB
testcase_57 AC 131 ms
7,604 KB
testcase_58 AC 193 ms
8,168 KB
testcase_59 AC 123 ms
7,348 KB
testcase_60 AC 250 ms
10,540 KB
testcase_61 AC 240 ms
9,328 KB
testcase_62 AC 250 ms
9,600 KB
testcase_63 AC 187 ms
8,192 KB
testcase_64 AC 23 ms
6,632 KB
testcase_65 AC 79 ms
6,980 KB
testcase_66 AC 223 ms
8,616 KB
testcase_67 AC 250 ms
10,856 KB
testcase_68 AC 246 ms
9,380 KB
testcase_69 AC 191 ms
8,040 KB
testcase_70 AC 172 ms
7,788 KB
testcase_71 AC 221 ms
8,368 KB
testcase_72 AC 86 ms
6,992 KB
testcase_73 AC 237 ms
8,956 KB
testcase_74 AC 13 ms
6,620 KB
testcase_75 AC 58 ms
6,812 KB
testcase_76 AC 179 ms
7,844 KB
testcase_77 AC 233 ms
9,532 KB
testcase_78 AC 219 ms
8,944 KB
testcase_79 AC 136 ms
7,828 KB
testcase_80 AC 246 ms
10,636 KB
testcase_81 AC 245 ms
10,460 KB
testcase_82 AC 191 ms
8,520 KB
testcase_83 AC 248 ms
10,332 KB
testcase_84 AC 235 ms
10,088 KB
testcase_85 AC 86 ms
7,144 KB
testcase_86 AC 29 ms
6,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


template<typename V>
V compress(V vs){
  sort(vs.begin(),vs.end());
  vs.erase(unique(vs.begin(),vs.end()),vs.end());
  return vs;
}
template<typename T>
map<T, int> dict(const vector<T> &vs){
  map<T, int> res;
  for(int i=0;i<(int)vs.size();i++)
    res[vs[i]]=i;
  return res;
}
map<char, int> dict(const string &s){
  return dict(vector<char>(s.begin(),s.end()));
}

//INSERT ABOVE HERE
const int MAX = 1e5+10;
using ll = long long;
ll bs[MAX];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n,m;
  cin>>n>>m;
  // auto bs=read(n);
  for(int i=0;i<n;i++) cin>>bs[i];

  vector<int> ls(m),rs(m);
  for(int i=0;i<m;i++) cin>>ls[i]>>rs[i],ls[i]--;

  vector<vector<int>> G(n);
  for(int i=0;i<m;i++)
    G[ls[i]].emplace_back(rs[i]);

  for(int i=0;i<n;i++){
    auto &vs=G[i];
    if(vs.empty()) continue;
    vs=compress(vs);
    for(int j=0;j+1<(int)vs.size();j++)
      G[vs[j]].emplace_back(vs[j+1]);

    if(bs[i]==0) continue;

    int x=i,y=vs[0],z=bs[i];
    for(int j=x;j<y;j++)
      bs[j]+=(j-x)&1?+z:-z;
  }
  for(int i=0;i<n;i++)
    if(bs[i]) drop("NO");
  drop("YES");
  return 0;
}
0