結果

問題 No.1347 HS Railway
ユーザー shiomusubi496shiomusubi496
提出日時 2021-01-16 14:56:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 174,792 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-05-05 17:36:10
合計ジャッジ時間 6,462 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 36 ms
5,376 KB
testcase_13 AC 29 ms
5,376 KB
testcase_14 AC 17 ms
5,376 KB
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 49 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 68 ms
5,376 KB
testcase_19 AC 59 ms
5,376 KB
testcase_20 AC 62 ms
5,376 KB
testcase_21 AC 31 ms
5,376 KB
testcase_22 AC 76 ms
5,444 KB
testcase_23 AC 66 ms
5,376 KB
testcase_24 AC 26 ms
5,376 KB
testcase_25 AC 46 ms
5,376 KB
testcase_26 AC 70 ms
5,376 KB
testcase_27 AC 40 ms
5,376 KB
testcase_28 AC 84 ms
6,016 KB
testcase_29 AC 79 ms
5,376 KB
testcase_30 AC 67 ms
5,376 KB
testcase_31 AC 61 ms
5,376 KB
testcase_32 AC 81 ms
5,376 KB
testcase_33 AC 92 ms
5,632 KB
testcase_34 AC 87 ms
5,560 KB
testcase_35 AC 87 ms
5,632 KB
testcase_36 AC 89 ms
5,504 KB
testcase_37 AC 105 ms
5,760 KB
testcase_38 AC 103 ms
5,760 KB
testcase_39 AC 106 ms
5,760 KB
testcase_40 AC 83 ms
5,376 KB
testcase_41 AC 80 ms
5,376 KB
testcase_42 AC 91 ms
5,888 KB
testcase_43 AC 74 ms
5,632 KB
testcase_44 AC 76 ms
5,376 KB
testcase_45 AC 75 ms
5,376 KB
testcase_46 AC 85 ms
6,016 KB
testcase_47 AC 88 ms
5,632 KB
testcase_48 AC 102 ms
6,656 KB
testcase_49 AC 90 ms
5,760 KB
testcase_50 AC 94 ms
6,272 KB
testcase_51 AC 86 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
int N,M,L[5],R[5],A[5][100100],ans;
vector<int>T[5];
signed main(){
  cin>>N;
  for(int i=0;i<5;i++){
    cin>>L[i]>>R[i];--L[i];--R[i];
    for(int j=L[i];j<R[i];j++)cin>>A[i][j];
  }
  cin>>M;
  for(int i=0;i<M;i++){
    int a,b;cin>>a>>b;
    T[--a].push_back(b);
  }
  for(int i=0;i<5;i++)sort(T[i].begin(),T[i].end());
  for(int i=0;i<5;i++)for(int j=i+1;j<5;j++){
    if(R[j]<L[i]||R[i]<L[j])continue;
    bool ok=L[i]>L[j];
    if(ok)swap(i,j);
    if(R[i]<R[j]){
      int left=0,right=0;
      for(int k=L[i];k<L[j];k++)left+=A[i][k];
      for(int k=L[i];k<R[i];k++)right+=A[i][k];
      for(int k=L[j];k<R[i];k++)right-=A[j][k];
      for(int k:T[i]){
        ans+=(upper_bound(T[j].begin(),T[j].end(),k+max(left,right))
             -lower_bound(T[j].begin(),T[j].end(),k+min(left,right)));
      }
    }else{
      int left=0,right=0;
      for(int k=L[i];k<L[j];k++)left+=A[i][k];
      for(int k=L[i];k<R[j];k++)right+=A[i][k];
      for(int k=L[j];k<R[j];k++)right-=A[j][k];
      for(int k:T[i]){
        ans+=(upper_bound(T[j].begin(),T[j].end(),k+max(left,right))
             -lower_bound(T[j].begin(),T[j].end(),k+min(left,right)));
      }
    }
    if(ok)swap(i,j);
  }
  cout<<ans<<endl;
}
0