結果
問題 | No.1919 Many Monster Battles |
ユーザー | 👑 hos.lyric |
提出日時 | 2022-04-29 22:05:05 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 6,209 bytes |
コンパイル時間 | 1,698 ms |
コンパイル使用メモリ | 122,628 KB |
実行使用メモリ | 67,796 KB |
最終ジャッジ日時 | 2024-06-29 03:34:06 |
合計ジャッジ時間 | 34,825 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,884 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 5 ms
6,940 KB |
testcase_04 | AC | 5 ms
6,940 KB |
testcase_05 | AC | 5 ms
6,940 KB |
testcase_06 | AC | 5 ms
6,940 KB |
testcase_07 | AC | 5 ms
6,940 KB |
testcase_08 | AC | 5 ms
6,940 KB |
testcase_09 | AC | 4 ms
6,944 KB |
testcase_10 | AC | 5 ms
6,940 KB |
testcase_11 | AC | 5 ms
6,944 KB |
testcase_12 | AC | 5 ms
6,940 KB |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 142 ms
11,552 KB |
testcase_28 | AC | 143 ms
11,680 KB |
testcase_29 | AC | 141 ms
11,556 KB |
testcase_30 | AC | 141 ms
11,548 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | TLE | - |
testcase_34 | -- | - |
ソースコード
#include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } //////////////////////////////////////////////////////////////////////////////// template <unsigned M_> struct ModInt { static constexpr unsigned M = M_; unsigned x; constexpr ModInt() : x(0U) {} constexpr ModInt(unsigned x_) : x(x_ % M) {} constexpr ModInt(unsigned long long x_) : x(x_ % M) {} constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {} constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {} ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; } ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; } ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; } ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); } ModInt pow(long long e) const { if (e < 0) return inv().pow(-e); ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b; } ModInt inv() const { unsigned a = M, b = x; int y = 0, z = 1; for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; } assert(a == 1U); return ModInt(y); } ModInt operator+() const { return *this; } ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; } ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); } ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); } ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); } ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); } template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); } template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); } template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); } template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); } explicit operator bool() const { return x; } bool operator==(const ModInt &a) const { return (x == a.x); } bool operator!=(const ModInt &a) const { return (x != a.x); } friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; } }; //////////////////////////////////////////////////////////////////////////////// constexpr unsigned MO = 1'000'000'007; using Mint = ModInt<MO>; int N; vector<pair<Int, Int>> P; Mint solve() { sort(P.begin(), P.end()); // cerr<<"P = ";pv(P.begin(),P.end()); vector<Int> xs(N); for (int i = 0; i < N; ++i) { const Int x = P[i].first - P[i].second; xs[i] = x; } sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); const int xsLen = xs.size(); // cerr<<" xs = ";pv(xs.begin(),xs.end()); vector<vector<Int>> yss(xsLen); for (int i = 0; i < N; ++i) { const Int x = P[i].first - P[i].second; const Int y = P[i].first + P[i].second; const int posX = lower_bound(xs.begin(), xs.end(), x) - xs.begin(); for (int e = posX; e < xsLen; e |= e + 1) { yss[e].push_back(y); } } vector<vector<Mint>> bit1(xsLen), bitA(xsLen); for (int e = 0; e < xsLen; ++e) { auto &ys = yss[e]; sort(ys.begin(), ys.end()); ys.erase(unique(ys.begin(), ys.end()), ys.end()); const int ysLen = ys.size(); bit1[e].assign(ysLen, 0); bitA[e].assign(ysLen, 0); } Mint ans = 0; for (int i = 0, j; i < N; ++i) { for (j = i; j < N && P[i].first == P[j].first; ++j) {} for (int k = i; k < j; ++k) { const Int x = P[k].first - P[k].second; const Int y = P[k].first + P[k].second; // cerr<<" get "<<k<<"; "<<x<<" "<<y<<endl; const int posX = lower_bound(xs.begin(), xs.end(), x) - xs.begin(); Mint sum1 = 0, sumA = 0; for (int e = posX - 1; e >= 0; e = (e & (e + 1)) - 1) { auto &ys = yss[e]; const int posY = lower_bound(ys.begin(), ys.end(), y) - ys.begin(); for (int f = posY - 1; f >= 0; f = (f & (f + 1)) - 1) { sum1 += bit1[e][f]; sumA += bitA[e][f]; } } ans += (sum1 * P[k].first - sumA); } for (int k = i; k < j; ++k) { const Int x = P[k].first - P[k].second; const Int y = P[k].first + P[k].second; // cerr<<" add "<<k<<"; "<<x<<" "<<y<<endl; const int posX = lower_bound(xs.begin(), xs.end(), x) - xs.begin(); for (int e = posX; e < xsLen; e |= e + 1) { auto &ys = yss[e]; const int posY = lower_bound(ys.begin(), ys.end(), y) - ys.begin(); for (int f = posY; f < (int)ys.size(); f |= f + 1) { bit1[e][f] += 1; bitA[e][f] += P[k].first; } } } } ans *= 2; return ans; } int main() { for (; ~scanf("%d", &N); ) { P.resize(N); for (int i = 0; i < N; ++i) scanf("%lld", &P[i].first); for (int i = 0; i < N; ++i) scanf("%lld", &P[i].second); const Mint ansA = solve(); for (int i = 0; i < N; ++i) swap(P[i].first, P[i].second); const Mint ansB = solve(); for (int i = 0; i < N; ++i) swap(P[i].first, P[i].second); printf("%u %u\n", ansA.x, ansB.x); } return 0; }