結果

問題 No.2160 みたりのDominator
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-12-11 02:02:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 7,189 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 112,104 KB
実行使用メモリ 15,644 KB
最終ジャッジ日時 2023-08-05 03:58:48
合計ジャッジ時間 7,901 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 11 ms
11,240 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 10 ms
11,168 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,384 KB
testcase_39 AC 2 ms
4,384 KB
testcase_40 AC 25 ms
11,348 KB
testcase_41 AC 22 ms
10,968 KB
testcase_42 AC 14 ms
7,804 KB
testcase_43 AC 20 ms
9,524 KB
testcase_44 AC 25 ms
10,972 KB
testcase_45 AC 24 ms
11,352 KB
testcase_46 AC 21 ms
10,936 KB
testcase_47 AC 14 ms
7,796 KB
testcase_48 AC 19 ms
9,272 KB
testcase_49 AC 23 ms
11,000 KB
testcase_50 AC 21 ms
11,356 KB
testcase_51 AC 16 ms
8,452 KB
testcase_52 AC 21 ms
10,296 KB
testcase_53 AC 25 ms
11,072 KB
testcase_54 AC 15 ms
7,648 KB
testcase_55 AC 95 ms
13,364 KB
testcase_56 AC 90 ms
12,440 KB
testcase_57 AC 92 ms
12,520 KB
testcase_58 AC 96 ms
15,004 KB
testcase_59 AC 95 ms
13,092 KB
testcase_60 AC 95 ms
15,196 KB
testcase_61 AC 95 ms
12,936 KB
testcase_62 AC 97 ms
15,644 KB
testcase_63 AC 94 ms
13,668 KB
testcase_64 AC 92 ms
13,264 KB
testcase_65 AC 37 ms
10,112 KB
testcase_66 AC 46 ms
9,944 KB
testcase_67 AC 46 ms
10,032 KB
testcase_68 AC 87 ms
14,268 KB
testcase_69 AC 64 ms
11,532 KB
testcase_70 AC 83 ms
14,496 KB
testcase_71 AC 28 ms
9,596 KB
testcase_72 AC 52 ms
12,872 KB
testcase_73 AC 92 ms
13,604 KB
testcase_74 AC 89 ms
13,140 KB
testcase_75 AC 8 ms
8,432 KB
testcase_76 AC 7 ms
7,524 KB
testcase_77 AC 40 ms
12,696 KB
testcase_78 AC 50 ms
13,244 KB
testcase_79 AC 6 ms
5,948 KB
testcase_80 AC 7 ms
6,600 KB
testcase_81 AC 10 ms
9,416 KB
testcase_82 AC 13 ms
9,848 KB
testcase_83 AC 19 ms
9,912 KB
61_evil_bias_nocross_01.txt AC 25 ms
11,212 KB
61_evil_bias_nocross_02.txt AC 22 ms
11,020 KB
61_evil_bias_nocross_03.txt AC 15 ms
7,812 KB
61_evil_bias_nocross_04.txt AC 19 ms
9,120 KB
61_evil_bias_nocross_05.txt AC 23 ms
11,044 KB
61_evil_bias_nocross_06.txt AC 24 ms
11,304 KB
61_evil_bias_nocross_07.txt AC 15 ms
8,360 KB
61_evil_bias_nocross_08.txt AC 20 ms
10,440 KB
61_evil_bias_nocross_09.txt AC 25 ms
10,880 KB
61_evil_bias_nocross_10.txt AC 13 ms
7,572 KB
61_evil_bias_nocross_11.txt AC 17 ms
8,996 KB
61_evil_bias_nocross_12.txt AC 23 ms
10,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
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; }


int N[3], M;
vector<int> U, V;

int main() {
  for (; ~scanf("%d%d%d%d", &N[0], &N[1], &N[2], &M); ) {
    for (int h = 0; h < 3; ++h) {
      ++N[h];
    }
    U.resize(M);
    V.resize(M);
    for (int m = 0; m < M; ++m) {
      scanf("%d%d", &U[m], &V[m]);
    }
    
    const int src = (N[0] - 1) + (N[1] - 1) + (N[2] - 1) + 1;
    const int snk = src + 1;
    const int offs[3] = {0, (N[0] - 1), (N[0] - 1) + (N[1] - 1)};
    auto decode = [&](int h, int u) -> int {
      if (u == src) return 0;
      if (u == snk) return N[h];
      u -= offs[h];
      if (0 < u && u < N[h]) return u;
      return -1;
    };
    vector<pair<int, int>> pss[3][3];
    for (int m = 0; m < M; ++m) {
      for (int h0 = 0; h0 < 3; ++h0) for (int h1 = h0; h1 < 3; ++h1) {
        {
          const int u = decode(h0, U[m]);
          const int v = decode(h1, V[m]);
          if (~u && ~v && (h0 < h1 || u < v)) {
            pss[h0][h1].emplace_back(u, v);
          }
        }
        {
          const int u = decode(h0, V[m]);
          const int v = decode(h1, U[m]);
          if (~u && ~v && (h0 < h1 || u < v)) {
            pss[h0][h1].emplace_back(u, v);
          }
        }
      }
    }
// for(int h0=0;h0<3;++h0)for(int h1=h0;h1<3;++h1)cerr<<"pss["<<h0<<"]["<<h1<<"] = "<<pss[h0][h1]<<endl;
    
    // (h, h)
    vector<int> fss[3], gss[3];
    for (int h = 0; h < 3; ++h) {
      fss[h].assign(N[h] + 1, 0);
      for (const auto &p : pss[h][h]) {
        ++fss[h][p.first];
        --fss[h][p.second];
      }
      for (int x = 0; x < N[h]; ++x) {
        fss[h][x + 1] += fss[h][x];
      }
      gss[h].assign(N[h] + 1, 0);
      for (int x = 0; x < N[h]; ++x) {
        gss[h][x + 1] = gss[h][x] + ((!fss[h][x]) ? 1 : 0);
      }
// cerr<<"fss["<<h<<"] = "<<fss[h]<<endl;
// cerr<<"gss["<<h<<"] = "<<gss[h]<<endl;
    }
    
    vector<int> lsss[3][3], rsss[3][3];
    for (int h0 = 0; h0 < 3; ++h0) for (int h1 = h0 + 1; h1 < 3; ++h1) {
      lsss[h0][h1].assign(N[h0], 0);
      rsss[h0][h1].assign(N[h0], N[h1]);
      for (const auto &p : pss[h0][h1]) {
        if (0 < p.first) {
          chmin(rsss[h0][h1][p.first - 1], p.second);
        }
        if (p.first < N[h0]) {
          chmax(lsss[h0][h1][p.first], p.second);
        }
      }
      for (int x = 0; x < N[h0] - 1; ++x) {
        chmax(lsss[h0][h1][x + 1], lsss[h0][h1][x]);
      }
      for (int x = N[h0]; --x >= 1; ) {
        chmin(rsss[h0][h1][x - 1], rsss[h0][h1][x]);
      }
    }
    {
      const int h0 = 2;
      const int h1 = 1;
      lsss[h0][h1].assign(N[h0], 0);
      rsss[h0][h1].assign(N[h0], N[h1]);
      for (const auto &p : pss[h1][h0]) {  // !
        if (0 < p.second) {
          chmin(rsss[h0][h1][p.second - 1], p.first);
        }
        if (p.second < N[h0]) {
          chmax(lsss[h0][h1][p.second], p.first);
        }
      }
      for (int x = 0; x < N[h0] - 1; ++x) {
        chmax(lsss[h0][h1][x + 1], lsss[h0][h1][x]);
      }
      for (int x = N[h0]; --x >= 1; ) {
        chmin(rsss[h0][h1][x - 1], rsss[h0][h1][x]);
      }
    }
/*
for(int h0=0;h0<3;++h0)for(int h1=0;h1<3;++h1)if(!lsss[h0][h1].empty()){
 cerr<<"lsss["<<h0<<"]["<<h1<<"] = "<<lsss[h0][h1]<<endl;
 cerr<<"rsss["<<h0<<"]["<<h1<<"] = "<<rsss[h0][h1]<<endl;
}
//*/
    
    // (1, 2)
    vector<int> headss[3];
    vector<Int> sumss[3];
    for (int h = 1; h < 3; ++h) {
      headss[h].assign(N[h] + 1, 0);
      for (int x = 0; x < N[h]; ++x) {
        headss[h][x + 1] = x + 1;
        if (x + 1 < N[h] &&
            lsss[h][h ^ 3][x] == lsss[h][h ^ 3][x + 1] &&
            rsss[h][h ^ 3][x] == rsss[h][h ^ 3][x + 1]) {
          headss[h][x + 1] = headss[h][x];
        }
      }
      sumss[h].assign(N[h] + 1, 0);
      for (int x = 0; x < N[h]; ++x) {
        sumss[h][x + 1] = sumss[h][x];
        if (!fss[h][x]) {
          const int l = lsss[h][h ^ 3][x];
          const int r = rsss[h][h ^ 3][x];
          if (l < r) {
            sumss[h][x + 1] += (gss[h ^ 3][r] - gss[h ^ 3][l]);
          }
        }
      }
// cerr<<"headss["<<h<<"] = "<<headss[h]<<endl;
// cerr<<"sumss["<<h<<"] = "<<sumss[h]<<endl;
    }
    
    auto calc = [&](int x1, int x2) -> Int {
      Int ret = 0;
      if (x2 == N[2] || x1 < lsss[2][1][x2]) {
        ret += sumss[1][x1];
      } else if (x1 == N[1] || x2 < lsss[1][2][x1]) {
        ret += sumss[2][x2];
      } else {
        const int xx1 = headss[1][x1];
        const int xx2 = headss[2][x2];
        ret += sumss[1][xx1];
        const int l1 = max(xx1, lsss[2][1][xx2]);
        const int r1 = min(x1 , rsss[2][1][xx2]);
        const int l2 = max(xx2, lsss[1][2][xx1]);
        const int r2 = min(x2 , rsss[1][2][xx1]);
        if (l1 < r1 && l2 < r2) {
          ret += (Int)(gss[1][r1] - gss[1][l1]) * (gss[2][r2] - gss[2][l2]);
        }
      }
// if(N[0]<=10)cerr<<"calc "<<x1<<" "<<x2<<" = "<<ret<<endl;
      return ret;
    };
    Int ans = 0;
    for (int x0 = 0; x0 < N[0]; ++x0) if (!fss[0][x0]) {
      if (lsss[0][1][x0] < rsss[0][1][x0] && lsss[0][2][x0] < rsss[0][2][x0]) {
        ans += calc(lsss[0][1][x0], lsss[0][2][x0]);
        ans -= calc(lsss[0][1][x0], rsss[0][2][x0]);
        ans -= calc(rsss[0][1][x0], lsss[0][2][x0]);
        ans += calc(rsss[0][1][x0], rsss[0][2][x0]);
      }
    }
    printf("%lld\n", ans);
    
#ifdef LOCAL
if((Int)N[0]*N[1]*N[2]<=1000){
 Int brt=0;
 {
  int xs[3];
  for(xs[0]=0;xs[0]<N[0];++xs[0])
  for(xs[1]=0;xs[1]<N[1];++xs[1])
  for(xs[2]=0;xs[2]<N[2];++xs[2])
  {
   if ([&]() -> bool {
    for(int h0=0;h0<3;++h0)for(int h1=h0;h1<3;++h1){
     for(const auto &p:pss[h0][h1]){
      if((xs[h0]<p.first)!=(xs[h1]<p.second))return false;
     }
    }
    return true;
   }()) {
// cerr<<"ok ";pv(xs,xs+3);
    ++brt;
   }
  }
 }
 if(brt!=ans){
  cerr<<"N = ";pv(N,N+3);
  cerr<<"U = "<<U<<endl;
  cerr<<"V = "<<V<<endl;
  for(int h0=0;h0<3;++h0)for(int h1=h0;h1<3;++h1)cerr<<"pss["<<h0<<"]["<<h1<<"] = "<<pss[h0][h1]<<endl;
  cerr<<"brt = "<<brt<<", ans = "<<ans<<endl;
  assert(false);
 }
}
#endif
  }
  return 0;
}
0