結果

問題 No.1347 HS Railway
ユーザー SSRSSSRS
提出日時 2021-01-16 14:07:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,348 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 180,208 KB
実行使用メモリ 10,516 KB
最終ジャッジ日時 2023-08-18 10:50:39
合計ジャッジ時間 7,158 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 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,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 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,380 KB
testcase_12 AC 41 ms
7,636 KB
testcase_13 AC 30 ms
4,604 KB
testcase_14 AC 17 ms
4,464 KB
testcase_15 AC 31 ms
8,008 KB
testcase_16 AC 53 ms
6,364 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 77 ms
9,716 KB
testcase_19 AC 63 ms
5,408 KB
testcase_20 AC 67 ms
8,684 KB
testcase_21 AC 34 ms
7,260 KB
testcase_22 AC 82 ms
9,724 KB
testcase_23 AC 70 ms
6,236 KB
testcase_24 AC 29 ms
5,380 KB
testcase_25 AC 50 ms
6,456 KB
testcase_26 AC 76 ms
7,860 KB
testcase_27 AC 47 ms
9,020 KB
testcase_28 AC 89 ms
9,768 KB
testcase_29 AC 85 ms
9,164 KB
testcase_30 AC 73 ms
9,692 KB
testcase_31 AC 66 ms
9,704 KB
testcase_32 AC 90 ms
10,516 KB
testcase_33 AC 100 ms
10,348 KB
testcase_34 AC 98 ms
10,280 KB
testcase_35 AC 95 ms
10,484 KB
testcase_36 AC 96 ms
10,324 KB
testcase_37 AC 110 ms
10,376 KB
testcase_38 AC 105 ms
10,512 KB
testcase_39 AC 108 ms
10,432 KB
testcase_40 AC 89 ms
10,432 KB
testcase_41 AC 89 ms
10,288 KB
testcase_42 AC 108 ms
10,476 KB
testcase_43 AC 87 ms
10,336 KB
testcase_44 AC 89 ms
10,340 KB
testcase_45 AC 85 ms
10,480 KB
testcase_46 AC 95 ms
10,448 KB
testcase_47 AC 101 ms
10,508 KB
testcase_48 AC 116 ms
10,376 KB
testcase_49 AC 98 ms
10,280 KB
testcase_50 AC 109 ms
10,332 KB
testcase_51 AC 97 ms
10,332 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