Submission #1281612

#TimeUsernameProblemLanguageResultExecution timeMemory
1281612M_W_133개의 봉우리 (IOI25_triples)C++20
83.79 / 100
161 ms43024 KiB
#include "triples.h"
#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) a.begin(), a.end()

set<pair<pii, int>> S;

pair<pii, int> sor(int a, int b, int c) {
  int x = min({a, b, c});
  int z = max({a, b, c});
  int y = a + b + c - x - z;
  return {{x, y}, z};
}

long long count_triples(std::vector<int> T) {
  int n = T.size();
  ll ans = 0;
  rep(i, n) {
    int j = i + T[i];
    int k[4];
    if (j < n) {
      k[0] = i + T[j];
      k[1] = i - T[j];
      k[2] = j + T[j];
      k[3] = j - T[j];
      rep(c, 4) {
        if (i == j || i == k[c] || j == k[c]) continue;
        if (k[c] < 0 || k[c] >= n) continue;
        int x = T[i];
        int y = T[j];
        int z = T[k[c]];
        int a = abs(i - j);
        int b = abs(i - k[c]);
        int d = abs(j - k[c]);
        if ((x + y + z) != (2 * max({x, y, z}))) continue;
        if (sor(a, b, d) != sor(x, y, z)) continue;
        S.insert(sor(i, j, k[c]));
      }
    }
    j = i - T[i];
    if (j >= 0) {
      k[0] = i + T[j];
      k[1] = i - T[j];
      k[2] = j + T[j];
      k[3] = j - T[j];
      rep(c, 4) {
        if (i == j || i == k[c] || j == k[c]) continue;
        if (k[c] < 0 || k[c] >= n) continue;
        int x = T[i];
        int y = T[j];
        int z = T[k[c]];
        int a = abs(i - j);
        int b = abs(i - k[c]);
        int d = abs(j - k[c]);
        if ((x + y + z) != (2 * max({x, y, z}))) continue;
        if (sor(a, b, d) != sor(x, y, z)) continue;
        S.insert(sor(i, j, k[c]));
      }
    }
  }
  ans = (long long) S.size();
  // for (auto p: S) {
  //   cout << p.st.st << " " << p.st.nd << " " << p.nd << '\n';
  // }
  vector<int> jakie[2 * n + 1];
  vector<int> jakie2[2 * n + 1];
  int iter[n];
  int iter2[n];
  rep(i, n) {
    int x = T[i] - i + n;
    iter[i] = jakie[x].size();
    jakie[x].pb(i);
  }
  for (int i = n - 1; i >= 0; i--) {
    int x = T[i] + i;
    iter2[i] = jakie2[x].size();
    jakie2[x].pb(i);
  }
  rep(i, n) {
    int x = T[i] - i + n;
    int y = T[i] + i;
    int sz = jakie[x].size();
    int sz1 = jakie[y].size();
    if (sz <= sz1) {
      for (int it = iter[i] - 1; it >= 0; it--) {
        int j = jakie[x][it];
        int k = i + T[j];
        if (k < n && ((T[k] + T[j]) == T[i])) {
          if (T[k] == T[j]) continue;
          ans++;
        }
      }
    }
    else {
      for (int it = iter2[i] - 1; it >= 0; it--) {
        int k = jakie2[y][it];
        int j = i - T[k];
        if (j >= 0 && ((T[k] + T[j]) == T[i])) {
          if (T[k] == T[j]) continue;
          ans++;
        }
      }
    }
  }
  return ans;
}

std::vector<int> construct_range(int M, int K) {
  srand(8831);
  vector<int> pom = {5, 2, 3, 3, 1, 2, 1, 4, 3, 2, 7, 6, 5, 6, 3, 4, 1, 2, 1, 3};
  vector<int> pom2 = {41, 8, 29, 38, 5, 46, 13, 34, 43, 10, 51, 38, 39, 48, 5, 16, 3, 44, 13, 46, 21, 28, 29, 18, 25, 26, 61, 54, 23, 36, 31, 72, 33, 28, 15, 30, 5, 28, 65, 66, 9, 10, 23, 44, 71, 4, 5, 58, 17, 56, 1, 10, 53, 12, 49, 50, 5, 8, 7, 28, 55, 20, 43, 2, 23, 16, 15, 36, 37, 18, 35, 10, 31, 32, 13, 70, 11, 26, 27, 114, 115, 5, 21, 22, 19, 20, 25, 38, 57, 104, 25, 102, 11, 52, 101, 8, 97, 98, 47, 94, 95, 92, 93, 42, 1, 40, 87, 88, 3, 6, 5, 82, 81, 82, 11, 10, 29, 76, 77, 160, 155, 72, 71, 72, 21, 20, 153, 66, 67, 64, 65, 172, 143, 160, 161, 10, 143, 138, 165, 140, 53, 54, 137, 129, 135, 5, 147, 148, 45, 44, 45, 152, 143, 122, 149, 124, 147, 138, 117, 34, 119, 142, 189, 132, 115, 114, 207, 136, 127, 24, 109, 122, 107, 122, 155, 176, 203, 126, 117, 114, 115, 94, 121, 96, 119, 166, 187, 106, 107, 190, 85, 88, 87, 10, 1, 108, 155, 82, 95, 96, 95, 150, 171, 100, 99, 174, 145, 166, 143, 94, 169, 162, 161, 194, 165, 164, 135, 156, 204, 154, 159, 207, 157, 218, 79, 164, 33, 124, 123, 178, 143, 41, 259, 146, 41, 40, 43, 42, 135, 134, 251, 138, 137, 50, 51, 246, 195, 142, 55, 54, 241, 190, 127, 188, 162, 236, 151, 165, 166, 114, 168, 230, 117, 9, 177, 75, 225, 122, 176, 177, 221, 220, 79, 168, 243, 44, 215, 2, 213, 25, 188, 12, 268, 90, 89, 10, 93, 8, 16, 202, 18, 12, 97, 148, 1, 5, 204, 194, 193, 4, 107, 106, 215, 188, 25, 51, 34, 117, 183, 119, 207, 206, 17, 38, 42, 36, 13, 124, 173, 187, 130, 229, 29, 28, 49, 53, 47, 24, 74, 50, 26, 186, 57, 40, 39, 81, 43, 42, 35, 85, 11, 38, 149, 148, 72, 155, 43, 75, 76, 95, 78, 56, 98, 49, 25, 52, 161, 85, 86, 30, 81, 89, 11, 59, 60, 14, 62, 74, 73, 97, 19, 31, 69, 69, 70, 67, 3, 73, 38, 28, 40, 8, 42, 108, 5, 106, 114, 79, 116, 33, 17, 51, 99, 98, 204, 141, 45, 94, 9, 43, 44, 106, 98, 47, 132, 112, 111, 34, 104, 7, 31, 139, 10, 11, 160, 26, 9, 25, 2, 3, 4, 70, 6, 1, 17, 3, 2, 123, 72, 13, 14, 11, 59, 11, 10, 56, 8, 13, 98, 11, 51, 25, 26, 1, 22, 72, 4, 3, 69, 42, 34, 49, 8, 64, 12, 11, 12, 55, 42, 9, 44, 39, 38, 41, 36, 109, 25, 45, 44, 67, 42, 29, 28, 31, 30, 25, 60, 27, 34, 57, 56, 31, 54, 67, 16, 19, 64, 63, 86, 61, 46, 5, 70, 43, 50, 79, 54, 53, 76, 75};
  vector<int> ans;
  if (M == 20) {
    int il = M/20;
    rep(i, il) {
      for (auto x: pom) {
        ans.pb(x);
      }
    }
  }
  else {
    int il = M/500;
    rep(i, il) {
      for (auto x: pom2) {
        ans.pb(x);
      }
      // reverse(all(pom2));
    }
  }
  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...