제출 #1250011

#제출 시각아이디문제언어결과실행 시간메모리
1250011fadak-143개의 봉우리 (IOI25_triples)C++20
51 / 100
2008 ms52744 KiB
//#include "worldmap.h"
#include "triples.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse2")
#define ll long long
#define db double
#define ld long double
#define endl '\n'
#define eb emplace_back 
#define em emplace
#define pb push_back
#define pf push_front
#define pp pop_back
#define fr first
#define sc second
#define sz size
#define ir insert
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define all(x) x.begin() , x.end()
#define alice cout << "Alice" << endl
#define bob cout << "Bob" << endl
#define fo(x , y) for(ll i = x;i < y;i++)
using namespace std;
mt19937 rd(time(NULL));
//IOI 2025 problems
const ll mxn = 1e5+5;
const ll md=998244353;
//vector<int> g[mxn];
/* "souvenirs" -> 39 points for now
void buy_souvenirs(int N, ll P0) {
    if(N==2){transaction(P0-1) ;return;}
    if(N==3){
        auto x=transaction(P0-1);
        if(x.fr.sz()==1){ll vl=P0-1-x.sc; transaction(vl-1);transaction(vl-1);}
        else{ll vl= (P0-1-x.sc) ; vl+=(2-vl%2)%2;vl/=2; transaction(vl-1);}
        return;
    }
    vector<ll>cn(N,0) , vl(N);
    vl[0]=P0;
    for(int i =1;i < N;i++) {
        auto x =transaction(vl[i-1] - 1) ;
        for(int y: x.fr) cn[y]++;
        if(x.fr.sz() ==1) vl[i] = vl[i-1] - 1 -x.sc;
        else vl[i] = vl[i-1] - 2;
    }
    for(int i = 1; i<N;i++) {
        while(cn[i] <i) {
            transaction(vl[i]);
            cn[i]++;
        }
    }
}
*/
/* "World Map" -> 72 points for now
vector<vector<int>> regulate(vector<vector<int>> board) {
    int n= board.sz();
    int m=board[0].sz() ;
    int k = max(n,m);
    vector an=vector(k,vector<int> (k));
    for(int i=0;i<n;i++)for(int j = 0;j<m ;j++)an[i][j]=board[i][j];
    for(int i=0;i<k;i++){for(int j=0;j<k;j++){
        if(!an[i][j]){
            if(j>0&&an[i][j-1])an[i][j] =an[i][j-1];
            else if(i>0&&an[i-1][j]) an[i][j] =an[i-1][j];
            else assert(false);
        }
    }}
    return an;
}
bool vs[mxn] ;
vector<pair<int, bool>> st;
void dfs(int v, int pa=-1) {
    vs[v]=true;
    for(int u:g[v]) {
        if(vs[u])continue;
        st.pb({u,true});
        dfs(u,v);
        st.pb({v,false});
    }
}
vector<vector<int>> create_map(int N, int M , vector<int> A , vector<int> B) {
    for(int i = 1 ; i <= N ;i++) g[i].clear(); 
    fill(vs,vs + N+1, false) ;
    for(int i = 0 ;i < M;i++){g[A[i]].pb(B[i]) ;g[B[i]].pb(A[i]);}
    st=vector<pair<int,bool>>{{1,true}}; 
    dfs(1);
    vector ans=vector(N*3 +(N-1), vector<int> (N*2)) ;
    int x= 0;
    for(auto [v,fi]:st) {
        if(fi) {
            for(int j=0;j<3;j++){for(int k = 0; k < N*2;k++)ans[x+j][k]=v;}
            for(int j =0;j <g[v].sz() ;j++)ans[x+1][j*2] = g[v][j];
            x+=3;
        }
        else{
            for(int k =0;k<N*2;k++)ans[x][k]=v;
            x++;
        }
    }
    return regulate(ans) ;
}
*/
//"Triple Peaks" , goal -> 50
set<tuple<int, int , int>> sn;
inline bool works(int i , int j , int k , const vector<int> &H){
    int p[3] = {i , j , k};
    sort(p , p +3);
    i = p[0] , j = p[1] , k =p[2];
    if(0>i||i >=j || j >=k || k >=H.sz()) return false;
    if(j-i == H[k] && k - j == H[i]) return false;
    if(sn.count({i,j,k})) return false;
    int d[3] = {j - i , k - j , k -i};
    int h[3] = {H[i] , H[j] ,H[k]} ;
    sort(d , d+3);
    sort(h, h+3);
    if(d[0]==h[0] && d[1] == h[1] && d[2] == h[2]) {sn.em(i , j , k); return true;}
    return false;
}
struct comb{
    map<int, int> a;
    ll operator*(const comb& b)const{
        if(a.sz() > b.a.sz()) return b * *this;
        ll o=0;
        for(auto [i,v] :a) if(b.a.count(i)) o+=(ll)v*b.a.at(i);
        return o;
    }
    void insert(int v){a[v]++;}
    void remove(int v) {if(!--a[v]){a.erase(v);}}
};
ll count_triples(vector<int> H) {
   cerr << "count_triples(...)\n";
   const int N = H.sz();
   ll ct=0;
   vector<int> xm(N) , xp(N);
    for(int x = 0 ; x< N ; x++) {xm[x]=x-H[x]; xp[x] =x+H[x];}
    map<int, comb>lf, rt;
    for(int i =0 ; i < N;i++)rt[xp[i]].insert(xm[i]);
    for(int j = 0 ; j < N;j++){
        rt[xp[j]].remove(xm[j]);
        ct += lf[xm[j]] * rt[xp[j]];
        lf[xm[j]].insert(xp[j]);
    }
    cerr<<"pre-trivial: "<< ct<< endl;
    for(int i =0 ; i <N;i++){
        for(int j :{i + H[i], i-H[i]}){
            if(j < 0||j>=N)continue;
            for(int k :{i+H[j], i-H[j], j+H[j],j-H[j]}) ct+=works(i , j , k , H);
        }
    }
    cerr<< " = "<<ct<<endl;
    return ct;
}   
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...