結果

問題 No.1347 HS Railway
ユーザー shiomusubi496shiomusubi496
提出日時 2021-01-16 14:56:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 1,751 ms
コンパイル使用メモリ 173,668 KB
実行使用メモリ 6,396 KB
最終ジャッジ日時 2023-08-18 12:14:53
合計ジャッジ時間 7,225 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 39 ms
4,376 KB
testcase_13 AC 30 ms
4,380 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 28 ms
4,376 KB
testcase_16 AC 51 ms
4,584 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 73 ms
4,840 KB
testcase_19 AC 63 ms
4,728 KB
testcase_20 AC 68 ms
5,144 KB
testcase_21 AC 34 ms
4,380 KB
testcase_22 AC 81 ms
5,460 KB
testcase_23 AC 70 ms
4,756 KB
testcase_24 AC 28 ms
4,376 KB
testcase_25 AC 49 ms
4,376 KB
testcase_26 AC 75 ms
5,000 KB
testcase_27 AC 43 ms
4,376 KB
testcase_28 AC 90 ms
5,644 KB
testcase_29 AC 82 ms
5,116 KB
testcase_30 AC 69 ms
4,576 KB
testcase_31 AC 63 ms
4,780 KB
testcase_32 AC 88 ms
5,024 KB
testcase_33 AC 100 ms
5,376 KB
testcase_34 AC 95 ms
5,276 KB
testcase_35 AC 92 ms
5,300 KB
testcase_36 AC 94 ms
5,236 KB
testcase_37 AC 107 ms
5,520 KB
testcase_38 AC 103 ms
5,592 KB
testcase_39 AC 107 ms
5,776 KB
testcase_40 AC 86 ms
5,268 KB
testcase_41 AC 86 ms
5,048 KB
testcase_42 AC 100 ms
5,884 KB
testcase_43 AC 81 ms
5,544 KB
testcase_44 AC 82 ms
5,336 KB
testcase_45 AC 79 ms
5,364 KB
testcase_46 AC 92 ms
6,008 KB
testcase_47 AC 93 ms
5,600 KB
testcase_48 AC 109 ms
6,396 KB
testcase_49 AC 91 ms
5,736 KB
testcase_50 AC 101 ms
6,020 KB
testcase_51 AC 92 ms
5,456 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