Submission #1309472

#TimeUsernameProblemLanguageResultExecution timeMemory
1309472Faisal_Saqib3개의 봉우리 (IOI25_triples)C++20
11 / 100
57 ms20164 KiB
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <set>
#include "triples.h"
using namespace std;
typedef long long ll;
std::vector<int> construct_range(int M, int K)
{
    return {};
}
const int N=1e6+10;
vector<int> pos[N],pos1[N];
long long count_triples(std::vector<int> h)
{
    ll ans=0;
    ll n=h.size();
    for(int i=0;i<n;i++)pos[i].clear(),pos1[i].clear();
    // Case 1
    //       h[i] = k-i
    for(int i=0;i<n;i++)
    {
        // for(int k=i+2;k<n;k++)
        int k=i+h[i];
        if(k<n)
        {
            set<int> pj;
            pj.insert(i+h[k]);
            pj.insert(k-h[k]);
            for(auto&j:pj)
            {
                if(i<j and j<k and h[j]+h[k] == h[i])
                {
                    ans++;
                }
            }
        }
    }

    // Case 2
    //       h[k] = k-i
    for(int k=0;k<n;k++)
    {
        int i=k-h[k];
        if(i>=0)
        {
            set<int> pj;
            pj.insert(i+h[i]);
            pj.insert(k-h[i]);
            for(auto&j:pj)
            // for(auto j:pj)
            {
                if(i<j and j<k and h[j]+h[i] == h[k])
                {
                    ans++;
                }
            }
        }
    }
    // Case 3.1
    // h[j] = k-i 
    // h[i] = j-i 
    for(int i=0;i<n;i++)
    {
        int j=h[i]+i;
        if(j<n)
        {
            int k=i+h[j];
            if(i<j and j<k and k<n and h[i]+h[k]==h[j])
            {
                ans++;
            }
        }
    }

    for(int i=0;i<n;i++)
    {
        int v=i+h[i];
        if(0<=v and v<n)
        {
            pos[v].push_back(i);
        }
        v=i-h[i];
        if(0<=v and v<n)
        {
            pos1[v].push_back(i);
        }
    }
    for(int v=0;v<n;v++)
    {
        for(int&k:pos1[v])
        {
            for(int&i:pos[v])
            {
                if(i>=k)continue;
                int j=i+h[k];
                if(i<j and j<k and h[j]==k-i)
                {
                    ans++;
                }
            }
        }
    }
    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...