結果

問題 No.1679 マスゲーム
ユーザー keijakkeijak
提出日時 2021-09-13 02:21:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 3,729 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 57,920 KB
実行使用メモリ 6,156 KB
最終ジャッジ日時 2023-09-07 05:27:10
合計ジャッジ時間 2,506 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 14 ms
6,144 KB
testcase_04 AC 14 ms
6,080 KB
testcase_05 AC 13 ms
6,136 KB
testcase_06 AC 15 ms
6,144 KB
testcase_07 AC 17 ms
6,020 KB
testcase_08 AC 14 ms
6,136 KB
testcase_09 AC 14 ms
6,128 KB
testcase_10 AC 14 ms
6,140 KB
testcase_11 AC 14 ms
6,144 KB
testcase_12 AC 4 ms
6,060 KB
testcase_13 AC 8 ms
6,120 KB
testcase_14 AC 13 ms
6,156 KB
testcase_15 AC 12 ms
6,132 KB
testcase_16 AC 12 ms
6,092 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#pragma GCC target("avx2")

#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <type_traits>
#include <algorithm>
#include <utility>

namespace fastio {
#ifdef MY_DEBUG
#define fread_unlocked fread
#define fwrite_unlocked fwrite
#endif

static constexpr int SZ = 1 << 17;
char ibuf[SZ], obuf[SZ];
int pil = 0, pir = 0, por = 0;

inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread_unlocked(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
  pil = 0;
}

inline void rd(char &c) {
  if (pil + 32 > pir) load();
  c = ibuf[pil++];
}
template<typename T>
inline void rd(T &x) {
  if (pil + 32 > pir) load();
  char c;
  do c = ibuf[pil++];
  while (c < '-');
  [[maybe_unused]] bool minus = false;
  if constexpr (std::is_signed<T>::value == true) {
    if (c == '-') minus = true, c = ibuf[pil++];
  }
  x = 0;
  while (c >= '0') {
    x = x * 10 + (c & 15);
    c = ibuf[pil++];
  }
  if constexpr (std::is_signed<T>::value == true) {
    if (minus) x = -x;
  }
}
inline void rd() {}
template<typename Head, typename... Tail>
inline void rd(Head &head, Tail &... tail) {
  rd(head);
  rd(tail...);
}

inline void skip_space() {
  if (pil + 32 > pir) load();
  while (ibuf[pil] <= ' ') pil++;
}

inline void flush() {
  fwrite_unlocked(obuf, 1, por, stdout);
  por = 0;
}

struct Pre {
  char num[40000];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i * 4 + j] = n % 10 + '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

struct Post {
  Post() { std::atexit(flush); }
} post;

inline void wt(char c) {
  if (por > SZ - 32) flush();
  obuf[por++] = c;
}
inline void wt(bool b) {
  if (por > SZ - 32) flush();
  obuf[por++] = b ? '1' : '0';
}
template<typename T>
inline void wt(T x) {
  if (por > SZ - 32) flush();
  if (!x) {
    obuf[por++] = '0';
    return;
  }
  if constexpr (std::is_signed<T>::value == true) {
    if (x < 0) obuf[por++] = '-', x = -x;
  }
  int i = 12;
  char buf[16];
  while (x >= 10000) {
    memcpy(buf + i, pre.num + (x % 10000) * 4, 4);
    x /= 10000;
    i -= 4;
  }
  if (x < 100) {
    if (x < 10) {
      obuf[por] = '0' + x;
      ++por;
    } else {
      uint32_t q = (uint32_t(x) * 205) >> 11;
      uint32_t r = uint32_t(x) - q * 10;
      obuf[por] = '0' + q;
      obuf[por + 1] = '0' + r;
      por += 2;
    }
  } else {
    if (x < 1000) {
      memcpy(obuf + por, pre.num + (x << 2) + 1, 3);
      por += 3;
    } else {
      memcpy(obuf + por, pre.num + (x << 2), 4);
      por += 4;
    }
  }
  memcpy(obuf + por, buf + i + 4, 12 - i);
  por += 12 - i;
}

inline void wt() {}
template<typename Head, typename... Tail>
inline void wt(Head &&head, Tail &&... tail) {
  wt(head);
  wt(std::forward<Tail>(tail)...);
}
template<typename... Args>
inline void wtn(Args &&... x) {
  wt(std::forward<Args>(x)...);
  wt('\n');
}

}  // namespace fastio
using fastio::rd;
using fastio::skip_space;
using fastio::wt;
using fastio::wtn;
using i64 = long long;
using u32 = unsigned;

#ifdef MY_DEBUG
#include "debug_dump.hpp"
#else
#define DUMP(...)
#endif

using namespace std;

int m0[400020];
int m1[400020];
const int kOffset = 200010;

int main() {
  int n;
  rd(n);
  int mx = 0, mn = 2 * kOffset;
  for (int i = 0; i < n; ++i) {
    int a, b, t;
    rd(a, b, t);
    int x = b - t + kOffset;
    if (a == 0) {
      ++m0[x];
    } else {
      ++m1[x];
    }
    mx = std::max(mx, x);
    mn = std::min(mn, x);
  }
  i64 ans = 0;
  for (int i = mn; i <= mx; ++i) {
    ans += i64(m0[i]) * m1[i];
  }
  wtn(ans);
}
0