結果

問題 No.1347 HS Railway
ユーザー tnakao0123tnakao0123
提出日時 2021-01-20 16:16:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,920 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 98,252 KB
実行使用メモリ 6,304 KB
最終ジャッジ日時 2023-08-24 20:10:12
合計ジャッジ時間 5,354 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 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,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 18 ms
4,380 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 12 ms
4,380 KB
testcase_16 AC 23 ms
4,744 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 35 ms
4,812 KB
testcase_19 AC 31 ms
4,748 KB
testcase_20 AC 30 ms
5,092 KB
testcase_21 AC 14 ms
4,568 KB
testcase_22 AC 37 ms
5,488 KB
testcase_23 AC 32 ms
4,784 KB
testcase_24 AC 13 ms
4,384 KB
testcase_25 AC 24 ms
4,380 KB
testcase_26 AC 35 ms
5,032 KB
testcase_27 AC 21 ms
4,540 KB
testcase_28 AC 38 ms
5,824 KB
testcase_29 AC 37 ms
5,232 KB
testcase_30 AC 32 ms
4,716 KB
testcase_31 AC 29 ms
4,888 KB
testcase_32 AC 42 ms
5,012 KB
testcase_33 AC 46 ms
5,496 KB
testcase_34 AC 45 ms
5,328 KB
testcase_35 AC 43 ms
5,332 KB
testcase_36 AC 44 ms
5,492 KB
testcase_37 AC 49 ms
5,752 KB
testcase_38 AC 48 ms
5,756 KB
testcase_39 AC 50 ms
5,604 KB
testcase_40 AC 40 ms
5,008 KB
testcase_41 AC 40 ms
5,220 KB
testcase_42 AC 57 ms
5,888 KB
testcase_43 AC 43 ms
5,400 KB
testcase_44 AC 46 ms
5,240 KB
testcase_45 AC 43 ms
5,348 KB
testcase_46 AC 50 ms
6,048 KB
testcase_47 AC 54 ms
5,600 KB
testcase_48 AC 62 ms
6,304 KB
testcase_49 AC 51 ms
5,724 KB
testcase_50 AC 57 ms
6,248 KB
testcase_51 AC 51 ms
5,456 KB
権限があれば一括ダウンロードができます

ソースコード

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 < K; i++)
    for (int j = i + 1; j < K; 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