結果

問題 No.1347 HS Railway
ユーザー SSRSSSRS
提出日時 2021-01-16 14:07:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,348 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 181,964 KB
実行使用メモリ 10,736 KB
最終ジャッジ日時 2024-05-05 16:17:47
合計ジャッジ時間 6,340 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 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 1 ms
5,376 KB
testcase_12 AC 40 ms
7,692 KB
testcase_13 AC 29 ms
5,376 KB
testcase_14 AC 16 ms
5,376 KB
testcase_15 AC 30 ms
8,336 KB
testcase_16 AC 52 ms
6,476 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 72 ms
9,760 KB
testcase_19 AC 63 ms
5,820 KB
testcase_20 AC 69 ms
9,048 KB
testcase_21 AC 34 ms
7,296 KB
testcase_22 AC 81 ms
10,016 KB
testcase_23 AC 68 ms
6,560 KB
testcase_24 AC 28 ms
5,632 KB
testcase_25 AC 48 ms
6,536 KB
testcase_26 AC 78 ms
8,172 KB
testcase_27 AC 46 ms
9,324 KB
testcase_28 AC 90 ms
9,924 KB
testcase_29 AC 85 ms
9,320 KB
testcase_30 AC 73 ms
9,844 KB
testcase_31 AC 66 ms
9,868 KB
testcase_32 AC 89 ms
10,736 KB
testcase_33 AC 100 ms
10,484 KB
testcase_34 AC 98 ms
10,608 KB
testcase_35 AC 93 ms
10,476 KB
testcase_36 AC 92 ms
10,612 KB
testcase_37 AC 106 ms
10,476 KB
testcase_38 AC 103 ms
10,608 KB
testcase_39 AC 106 ms
10,640 KB
testcase_40 AC 86 ms
10,480 KB
testcase_41 AC 86 ms
10,608 KB
testcase_42 AC 99 ms
10,476 KB
testcase_43 AC 84 ms
10,608 KB
testcase_44 AC 87 ms
10,480 KB
testcase_45 AC 80 ms
10,576 KB
testcase_46 AC 90 ms
10,608 KB
testcase_47 AC 97 ms
10,608 KB
testcase_48 AC 112 ms
10,608 KB
testcase_49 AC 95 ms
10,480 KB
testcase_50 AC 102 ms
10,736 KB
testcase_51 AC 91 ms
10,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> L(5), R(5);
  vector<vector<int>> A(5, vector<int>(N - 1, 0));
  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];
    }
  }
  int M;
  cin >> M;
  vector<vector<int>> s(5);
  for (int i = 0; i < M; i++){
    int B, S;
    cin >> B >> S;
    B--;
    s[B].push_back(S);
  }
  for (int i = 0; i < 5; i++){
    sort(s[i].begin(), s[i].end());
  }
  vector<vector<long long>> T(5, vector<long long>(N));
  for (int i = 0; i < 5; i++){
    T[i][0] = 0;
    for (int j = 0; j < N - 1; j++){
      T[i][j + 1] = T[i][j] + A[i][j];
    }
  }
  long long ans = 0;
  for (int i = 0; i < 5; i++){
    for (int j = 0; j < i; j++){
      int l = max(L[i], L[j]);
      int r = min(R[i], R[j]);
      if (l < r){
        vector<long long> lj, rj;
        for (int x : s[j]){
          lj.push_back(x + T[j][l]);
          rj.push_back(x + T[j][r]);
        }
        for (int x : s[i]){
          long long li = x + T[i][l];
          long long ri = x + T[i][r];
          int a = lower_bound(lj.begin(), lj.end(), li) - lj.begin();
          int b = upper_bound(rj.begin(), rj.end(), ri) - rj.begin();
          ans += b - a;
        }
      }
    }
  }
  cout << ans << endl;
}
0