結果

問題 No.1347 HS Railway
ユーザー mkawa2mkawa2
提出日時 2021-09-06 22:11:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,402 bytes
コンパイル時間 3,285 ms
コンパイル使用メモリ 210,748 KB
実行使用メモリ 6,720 KB
最終ジャッジ日時 2023-08-24 13:02:38
合計ジャッジ時間 10,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 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,380 KB
testcase_12 AC 16 ms
4,384 KB
testcase_13 AC 13 ms
4,384 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 11 ms
4,384 KB
testcase_16 AC 20 ms
4,604 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 29 ms
5,308 KB
testcase_19 AC 26 ms
4,752 KB
testcase_20 AC 26 ms
4,872 KB
testcase_21 AC 13 ms
4,492 KB
testcase_22 AC 32 ms
5,476 KB
testcase_23 AC 28 ms
4,756 KB
testcase_24 AC 12 ms
4,380 KB
testcase_25 AC 20 ms
4,380 KB
testcase_26 AC 30 ms
5,092 KB
testcase_27 AC 18 ms
4,384 KB
testcase_28 AC 33 ms
5,664 KB
testcase_29 AC 32 ms
5,140 KB
testcase_30 AC 28 ms
4,788 KB
testcase_31 AC 26 ms
4,764 KB
testcase_32 AC 35 ms
5,276 KB
testcase_33 AC 38 ms
5,804 KB
testcase_34 AC 37 ms
5,720 KB
testcase_35 AC 37 ms
5,504 KB
testcase_36 AC 37 ms
5,560 KB
testcase_37 AC 41 ms
6,012 KB
testcase_38 AC 40 ms
6,000 KB
testcase_39 AC 41 ms
6,076 KB
testcase_40 AC 34 ms
5,440 KB
testcase_41 AC 34 ms
5,568 KB
testcase_42 AC 40 ms
6,060 KB
testcase_43 AC 35 ms
5,736 KB
testcase_44 AC 35 ms
5,692 KB
testcase_45 AC 34 ms
5,700 KB
testcase_46 AC 38 ms
6,104 KB
testcase_47 AC 38 ms
5,908 KB
testcase_48 AC 45 ms
6,720 KB
testcase_49 AC 38 ms
6,200 KB
testcase_50 AC 42 ms
6,476 KB
testcase_51 AC 38 ms
5,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
const int inf = 1e9;
const ll lim = 1e18;
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n;
  vi l(5), r(5);
  vvll cs;
  rep(i, 5) {
    cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
    vll s(r[i] - l[i] + 1, 0);
    rep(j, r[i] - l[i]) {
      ll a;
      cin >> a;
      s[j + 1] = s[j] + a;
    }
    cs.push_back(s);
  }

  cin >> m;
  vvll ss(5);
  rep(_, m) {
    int i;
    ll s;
    cin >> i >> s;
    i--;
    ss[i].push_back(s);
  }
  rep(i, 5) sort(all(ss[i]));

  ll ans = 0;
  rep(j, 5) rep(i, j) {
    int L = max(l[i], l[j]);
    int R = min(r[i], r[j]);
    if (L > R) continue;
    int u = 0, v = 0;
    ll d = cs[j][L - l[j]] - cs[i][L - l[i]];
    ll e = cs[j][R - l[j]] - cs[i][R - l[i]];
    for (ll s : ss[j]) {
      while (u < ss[i].size() && s + d > ss[i][u]) u++;
      while (v < ss[i].size() && s + e >= ss[i][v]) v++;
      ans += v - u;
    }
  }
  cout<<ans<<endl;

  return 0;
}
0