Submission #939643

# Submission time Handle Problem Language Result Execution time Memory
939643 2024-03-06T15:58:36 Z haxorman Dancing Elephants (IOI11_elephants) C++14
Compilation error
0 ms 0 KB
#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN = 150007;
const int SZ = 388;

int n, l, step, pos[mxN], bkt[mxN], to[mxN], cnt[mxN], sz[SZ];
set<pair<int,int>> st;
pair<int,int> arr[mxN];

void fix(int b) {
    for (int i = arr[b].size()-1; i >= 0; --i) {
        int val = arr[b][i].first + l;

        if (val >= arr[b].back()) {
            to[arr[b][i].second] = val;
            cnt[arr[b][i].second] = 1;
        }
        else {
            auto it = upper_bound(arr[b].begin(), arr[b].end(),
                                                  make_pair(val,INT_MAX));

            to[arr[b][i].second] = to[(*it).second];
            cnt[arr[b][i].second] = cnt[(*it).second] + 1;
        }
    }
}

void construct() {
    for (int i = 0; i < SZ; ++i) {
        arr[i].clear();
    }
    
    auto it = st.begin();
    for (int i = 0; i < n; ++i) {
        bkt[(*it).second] = i/SZ;
        arr[i/SZ].push_back(*it);
        
        advance(it, 1);
    }

    for (int b = 0; b < SZ; ++b) {
        fix(b);
    }
}

void init(int N, int L, int X[]) {
    n = N, l = L;
    
    for (int i = 0; i < n; ++i) {
        pos[i] = X[i];
        st.insert({pos[i], i});
    }

    construct();
}

int update(int i, int y) {
    for (int j = 0; j < arr[bkt[i]].size(); ++j) {
        if (arr[bkt[i]][j].second == i) {
            arr[bkt[i]].erase(arr[bkt[i]].begin() + j);
            break;
        }
    }
    st.erase({pos[i], i});
    fix(bkt[i]);
    
    for (int b = 0; b < SZ; ++b) {
        if (b == SZ-1 || (arr[b].size() && arr[b].back().first > y)) {
            bkt[i] = b;
            arr[b].push_back({pos[i] = y, i});
            sort(arr[b].begin(), arr[b].end());
            
            st.insert({pos[i], i});
            fix(b);
            break;
        }
    }
    
    int ans = 0, cur = -1;
    for (int b = 0; b < SZ; ++b) {
        if (arr[b].size() && arr[b].back().first > cur) {
            auto it = upper_bound(arr[b].begin(), arr[b].end(),
                                                  make_pair(cur,INT_MAX));

            ans += cnt[(*it).second];
            cur = to[(*it).second];
        }
    }

    step++;
    if (step == SZ) {
        construct();
        step = 0;
    }
    return ans;
}

Compilation message

elephants.cpp: In function 'void fix(int)':
elephants.cpp:13:25: error: 'struct std::pair<int, int>' has no member named 'size'
   13 |     for (int i = arr[b].size()-1; i >= 0; --i) {
      |                         ^~~~
elephants.cpp:14:25: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   14 |         int val = arr[b][i].first + l;
      |                         ^
elephants.cpp:16:27: error: 'struct std::pair<int, int>' has no member named 'back'
   16 |         if (val >= arr[b].back()) {
      |                           ^~~~
elephants.cpp:17:22: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   17 |             to[arr[b][i].second] = val;
      |                      ^
elephants.cpp:18:23: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   18 |             cnt[arr[b][i].second] = 1;
      |                       ^
elephants.cpp:21:42: error: 'struct std::pair<int, int>' has no member named 'begin'
   21 |             auto it = upper_bound(arr[b].begin(), arr[b].end(),
      |                                          ^~~~~
elephants.cpp:21:58: error: 'struct std::pair<int, int>' has no member named 'end'
   21 |             auto it = upper_bound(arr[b].begin(), arr[b].end(),
      |                                                          ^~~
elephants.cpp:24:22: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   24 |             to[arr[b][i].second] = to[(*it).second];
      |                      ^
elephants.cpp:25:23: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   25 |             cnt[arr[b][i].second] = cnt[(*it).second] + 1;
      |                       ^
elephants.cpp: In function 'void construct()':
elephants.cpp:32:16: error: 'struct std::pair<int, int>' has no member named 'clear'
   32 |         arr[i].clear();
      |                ^~~~~
elephants.cpp:38:19: error: 'struct std::pair<int, int>' has no member named 'push_back'
   38 |         arr[i/SZ].push_back(*it);
      |                   ^~~~~~~~~
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:60:37: error: 'struct std::pair<int, int>' has no member named 'size'
   60 |     for (int j = 0; j < arr[bkt[i]].size(); ++j) {
      |                                     ^~~~
elephants.cpp:61:24: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   61 |         if (arr[bkt[i]][j].second == i) {
      |                        ^
elephants.cpp:62:25: error: 'struct std::pair<int, int>' has no member named 'erase'
   62 |             arr[bkt[i]].erase(arr[bkt[i]].begin() + j);
      |                         ^~~~~
elephants.cpp:62:43: error: 'struct std::pair<int, int>' has no member named 'begin'
   62 |             arr[bkt[i]].erase(arr[bkt[i]].begin() + j);
      |                                           ^~~~~
elephants.cpp:70:34: error: 'struct std::pair<int, int>' has no member named 'size'
   70 |         if (b == SZ-1 || (arr[b].size() && arr[b].back().first > y)) {
      |                                  ^~~~
elephants.cpp:70:51: error: 'struct std::pair<int, int>' has no member named 'back'
   70 |         if (b == SZ-1 || (arr[b].size() && arr[b].back().first > y)) {
      |                                                   ^~~~
elephants.cpp:72:20: error: 'struct std::pair<int, int>' has no member named 'push_back'
   72 |             arr[b].push_back({pos[i] = y, i});
      |                    ^~~~~~~~~
elephants.cpp:73:25: error: 'struct std::pair<int, int>' has no member named 'begin'
   73 |             sort(arr[b].begin(), arr[b].end());
      |                         ^~~~~
elephants.cpp:73:41: error: 'struct std::pair<int, int>' has no member named 'end'
   73 |             sort(arr[b].begin(), arr[b].end());
      |                                         ^~~
elephants.cpp:83:20: error: 'struct std::pair<int, int>' has no member named 'size'
   83 |         if (arr[b].size() && arr[b].back().first > cur) {
      |                    ^~~~
elephants.cpp:83:37: error: 'struct std::pair<int, int>' has no member named 'back'
   83 |         if (arr[b].size() && arr[b].back().first > cur) {
      |                                     ^~~~
elephants.cpp:84:42: error: 'struct std::pair<int, int>' has no member named 'begin'
   84 |             auto it = upper_bound(arr[b].begin(), arr[b].end(),
      |                                          ^~~~~
elephants.cpp:84:58: error: 'struct std::pair<int, int>' has no member named 'end'
   84 |             auto it = upper_bound(arr[b].begin(), arr[b].end(),
      |                                                          ^~~