結果

問題 No.1347 HS Railway
ユーザー tnakao0123tnakao0123
提出日時 2021-01-20 16:12:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,920 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 99,108 KB
実行使用メモリ 6,412 KB
最終ジャッジ日時 2023-08-24 20:06:12
合計ジャッジ時間 13,575 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 RE -
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 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 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 6 ms
4,380 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1347.cc:  No.1347 HS Railway - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int K = 5;
const int MAX_N = 100000;
const int MAX_M = 100000;

/* typedef */

typedef long long ll;
typedef vector<ll> vl;

/* global variables */

int ls[K], rs[K];
ll ass[K][MAX_N + 1];
vl sts[K];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < K; i++) {
    scanf("%d%d", ls + i, rs + i);
    ls[i]--, rs[i]--;
    for (int j = ls[i]; j < rs[i]; j++) {
      int a;
      scanf("%d", &a);
      ass[i][j + 1] = ass[i][j] + a;
    }
  }

  int m;
  scanf("%d", &m);

  for (int i = 0; i < m; i++) {
    int bi, si;
    scanf("%d%d", &bi, &si);
    bi--;
    sts[bi].push_back(si);
  }

  for (int i = 0; i < K; i++) {
    sort(sts[i].begin(), sts[i].end());
    //for (int j = 0; j < sts[i].size(); j++) printf("%lld ", sts[i][j]);
    //putchar('\n');
  }

  ll cnt = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      vl &sti = sts[i], &stj = sts[j];
      if (sti.empty() || stj.empty()) continue;

      int l = max(ls[i], ls[j]), r = min(rs[i], rs[j]);
      if (l >= r) continue;

      ll d0 = ass[j][l] - ass[i][l];
      ll d1 = ass[j][r] - ass[i][r];
      //printf("%d,%d: %d-%d, %lld,%lld\n", i, j, l, r, d0, d1);

      for (vl::iterator vit = stj.begin(); vit != stj.end(); vit++) {
	int x0 = lower_bound(sti.begin(), sti.end(), *vit + d0) - sti.begin();
	int x1 = upper_bound(sti.begin(), sti.end(), *vit + d1) - sti.begin();
	cnt += x1 - x0;
      }
    }

  printf("%lld\n", cnt);
  return 0;
}
0