Submission #1281596

#TimeUsernameProblemLanguageResultExecution timeMemory
1281596M_W_13Triple Peaks (IOI25_triples)C++20
83.30 / 100
162 ms43200 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 = {1, 2, 3, 2, 1, 6, 5, 6, 3, 4, 5, 8, 1, 2, 15, 14, 17, 16, 15, 14, 9, 8, 11, 10, 25, 26, 25, 24, 23, 28, 19, 20, 19, 1, 23, 36, 35, 34, 33, 10, 11, 30, 9, 14, 45, 12, 47, 46, 45, 50, 49, 48, 47, 76, 3, 44, 43, 2, 53, 30, 11, 10, 29, 30, 65, 64, 33, 62, 39, 20, 71, 70, 21, 68, 25, 24, 65, 64, 21, 28, 9, 70, 11, 84, 83, 86, 85, 54, 83, 78, 39, 80, 79, 36, 5, 46, 45, 98, 97, 42, 95, 100, 69, 92, 91, 106, 35, 108, 107, 58, 105, 60, 111, 102, 15, 116, 115, 116, 113, 114, 21, 110, 111, 124, 123, 126, 125, 124, 123, 118, 117, 120, 99, 82, 77, 6, 79, 86, 109, 140, 107, 90, 91, 72, 87, 134, 133, 48, 19, 98, 21, 100, 95, 60, 13, 56, 15, 58, 65, 88, 71, 62, 33, 70, 65, 66, 67, 7, 27, 2, 77, 42, 43, 74, 21, 76, 47, 36, 37, 50, 51, 52, 41, 12, 17, 44, 45, 46, 59, 90, 61, 24, 21, 22, 53, 28, 55, 26, 31, 32, 33, 30, 31, 8, 75, 10, 107, 40, 7, 38, 69, 40, 11, 18, 19, 14, 15, 16, 5, 4, 9, 26, 7, 8, 9, 54, 3, 4, 5, 18, 1, 16, 1, 18, 63, 12, 13, 14, 9, 8, 7, 10, 9, 12, 21, 34, 33, 32, 17, 2};
  vector<int> ans;
  if (M == 20) {
    int il = M/20;
    rep(i, il) {
      for (auto x: pom) {
        ans.pb(x);
      }
    }
  }
  else {
    int il = M/250;
    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...