Submission #1260377

#TimeUsernameProblemLanguageResultExecution timeMemory
1260377alexddTriple Peaks (IOI25_triples)C++20
70 / 100
272 ms41368 KiB
#include "triples.h"
#include<bits/stdc++.h>
using namespace std;
int n;
long long rez = 0;
map<tuple<int,int,int>,int> mp;
vector<int> h;
void add(int i, int j, int k)
{
    if(i >= j || j >= k)
        return;
    if(i < 0 || k >= n)
        return;
    if(h[k] == j-i && h[i] == k-j && h[j] == k-i) return;///caz special----------------------------------------------

    vector<int> v1 = {j-i,k-j,k-i};
    vector<int> v2 = {h[i],h[j],h[k]};
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());

    //if(min(j-i, k-j) == min({h[i],h[j],h[k]}) && k-i == max({h[i],h[j],h[k]}) && h[i] + h[j] + h[k] == 2 * max({h[i],h[j],h[k]}))
    if(v1 == v2)
    {
        if(mp[{i,j,k}] == 0)
            rez++;
        mp[{i,j,k}] = 1;
    }
}
vector<int> ofval[400005][2];
long long count_triples(std::vector<int> H)
{
    h = H;
    n = h.size();
    for(int j=0;j<n;j++)
    {
        if(j - h[j] >= 0) add(j - h[j], j, (j - h[j]) + h[j - h[j]]);
        if(j - h[j] >= 0) add(j - h[j], j, j + h[j - h[j]]);

        if(j + h[j] < n) add(j - h[j + h[j]], j, j + h[j]);
        if(j + h[j] < n) add((j + h[j]) - h[j + h[j]], j, j + h[j]);
    }
    for(int i=0;i<n;i++)
    {
        int j = i + h[i];
        if(j < n) add(i, j, i + h[j]);
    }

    for(int i=0;i<n;i++)
    {
        ofval[i + h[i]][0].push_back(i);
        ofval[i - h[i] + n][1].push_back(i);
    }

    for(int j=0;j<n;j++)
    {
        if(ofval[j + h[j]][0].size() <= ofval[j - h[j] + n][1].size())
        {
            for(int k:ofval[j + h[j]][0])
            {
                int i = j - h[k];
                if(i < j && j < k && i >= 0 && k < n && h[k] == j-i && h[i] == k-j && h[j] == k-i)
                    rez++;
            }
        }
        else
        {
            for(int i:ofval[j - h[j] + n][1])
            {
                int k = j + h[i];
                if(i < j && j < k && i >= 0 && k < n && h[k] == j-i && h[i] == k-j && h[j] == k-i)
                    rez++;
            }
        }
    }

    return rez;
}

std::vector<int> construct_range(int M, int K)
{
    return {};
}
#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...