Submission #1281592

#TimeUsernameProblemLanguageResultExecution timeMemory
1281592M_W_13Triple Peaks (IOI25_triples)C++20
81.04 / 100
162 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 = {1, 6, 5, 4, 3, 6, 5, 1, 9, 8, 9, 10, 5, 6, 3, 4, 5, 4, 1, 2, 1, 3, 23, 24, 23, 18, 19, 20, 17, 18, 29, 14, 15, 14, 13, 36, 35, 40, 39, 38, 39, 30, 35, 42, 33, 44, 1, 30, 29, 28, 39, 34, 33, 36, 35, 38, 37, 36, 41, 12, 39, 16, 15, 16, 17, 20, 19, 24, 21, 24, 23, 39, 27, 26, 3, 4, 5, 5, 1, 2, 9, 4, 3, 6, 5, 8, 7, 2, 11, 4, 9, 2, 7, 1, 5, 2, 3, 3, 1, 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/100;
    rep(i, il) {
      for (auto x: pom2) {
        ans.pb(x);
      }
    }
  }
  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...