Submission #1251350

#TimeUsernameProblemLanguageResultExecution timeMemory
1251350tranvinhhuy2010Triple Peaks (IOI25_triples)C++20
Compilation error
0 ms0 KiB
#include "triples.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int nmax = 2e5 + 5;
int n;
unordered_map <int, vector <int>> mk;

ll count_triples(vector <int> H) {
    n = H.size();
    ll cnt = 0;
    for (int j=0; j<n; j++) {
        // Hj = j - i
        int i = j - H[j];
        if (i>=0) {
            int k1 = i + H[i], k2 = j + H[i];
            if (k1<n && k1>j && H[k1]==k1-j) cnt++;
            if (k2<n && k2>j && H[k2]==k2-i) cnt++;
        }

        // Hj = k - j
        int k = j + H[j];
        if (k<n) {
            int i1 = j - H[k], i2 = k - H[k];
            if (i1>=0 && i1<j && H[i1]==k-i1) cnt++;
            if (i2>=0 && i2<j && H[i2]==j-i2) cnt++;
        }

        mk[j - H[j]].push_back(j);
    }

    for (int i=0; i<n; i++) {
        int j = i + H[i];
        if (j<=n) {
            int k = i + H[j];
            if (H[k]==k-j) cnt++;
        }
    }

    for (int i=0; i<n; i++) {
        mk[i - H[i]].erase(remove(mk[i - H[i]].begin(), mk[i - H[i]].end(), i), mk[i - H[i]].end());

        for (int k : mk[i + H[i]]) {
            int j = H[i] + H[k];
            if (j==k-i) cnt++;
        }
    }

    return cnt;
}

vector<int> construct_range(int M, int K) {
    vector<int> ans1 = {
        4,  3,  1,  2,  1,
        4,  3,  2,  7,  6,
        5,  8, 11, 10,  9,
        1,  7,  2,  3,  4,
    };

    if(M <= 20){
        while(ans1.size() > M || ans1.back() >= M) ans1.pop_back();
        return ans1;
    }
    vector<int> S = {0};
    vector<bool> in_span(2M, false);
    int span_cnt = 0;
    vector<pair<int,int>> pts;

    while(span_cnt < M-1) {
        int best_t = -1, best_gain = -1;
        vector<bool> inS(2M, false);
        for(int u:S) inS[u] = true;
        for(int t = 0; t <= 2(M-1); t += 2) if(!inS[t]) {
            int gain = 0;
            for(int u:S) {
                if(u==t) continue;
                int s = u + t;
                if(s >= 2 && s <= 2(M-1) && (s%2==0) && !in_span[s]) ++gain;
            }
            if(gain > best_gain) {
                best_gain = gain;
                best_t = t;
            }
        }
        if(best_t < 0) break;
        for(int u:S) {
            if(u == best_t) continue;
            int s = u + best_t;
            if(s >= 2 && s <= 2*(M-1) && (s%2==0) && !in_span[s]) {
                int x = min(u, best_t), y = max(u, best_t);
                pts.emplace_back(x, y);
                in_span[s] = true;
                ++span_cnt;
            }
        }
        S.push_back(best_t);
    }
    vector<int> H(M, 1);
    for(auto [x,y] : pts) {
        int idx = (x + y) / 2;
        int h   = (y - x) / 2;
        if(idx >= 0 && idx < M) {
            H[idx] = h;
        }
    }
    return H;
}

Compilation message (stderr)

triples.cpp: In function 'std::vector<int> construct_range(int, int)':
triples.cpp:68:26: error: unable to find numeric literal operator 'operator""M'
   68 |     vector<bool> in_span(2M, false);
      |                          ^~
triples.cpp:74:26: error: unable to find numeric literal operator 'operator""M'
   74 |         vector<bool> inS(2M, false);
      |                          ^~
triples.cpp:76:30: error: expression cannot be used as a function
   76 |         for(int t = 0; t <= 2(M-1); t += 2) if(!inS[t]) {
      |                             ~^~~~~
triples.cpp:81:36: error: expression cannot be used as a function
   81 |                 if(s >= 2 && s <= 2(M-1) && (s%2==0) && !in_span[s]) ++gain;
      |                                   ~^~~~~