답안 #1118527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1118527 2024-11-25T15:49:00 Z _callmelucian 코끼리 (Dancing Elephants) (IOI11_elephants) C++14
100 / 100
4383 ms 11764 KB
#include <bits/stdc++.h>
#include "elephants.h"
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;
 
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
 
const int blockSize = 500, resetCycle = 200, mn = 150'005;
int n, L, queryCount, save[mn];
 
struct block {
    vector<int> x, jumpTo, step;
 
    void refine() {
        int iter = x.size();
        for (int i = (int)x.size() - 1; i >= 0; i--) {
            while (iter - 1 >= 0 && x[iter - 1] - x[i] > L) iter--;
            if (iter == x.size()) jumpTo[i] = x[i] + L, step[i] = 1;
            else jumpTo[i] = jumpTo[iter], step[i] = step[iter] + 1;
        }
    }
 
    block (vector<int> x) : x(x), jumpTo(x.size()), step(x.size()) { refine(); }
 
    void insert (int xP) {
        x.insert(upper_bound(all(x), xP), xP);
        jumpTo.push_back(0), step.push_back(0);
        refine();
    }
 
    void remove (int xP) {
        x.erase(lower_bound(all(x), xP));
        jumpTo.pop_back(), step.pop_back();
        refine();
    }
 
    pii batchJump (int start) {
        int pos = upper_bound(all(x), start) - x.begin();
        if (pos == x.size()) return {start, 0};
        return {jumpTo[pos], step[pos]};
    }
 
    int last() { return x.back(); }
};
 
vector<block> blocks;
 
void build (const vector<int> &x) {
    for (int i = 0; i < x.size(); i += blockSize) {
        vector<int> cur(x.begin() + i, x.begin() + min((int)x.size(), i + blockSize));
        blocks.emplace_back(cur);
    }
}
 
void reBuild() {
    vector<int> x;
    for (block &cur : blocks)
        for (int u : cur.x) x.push_back(u);
    blocks.clear(), build(x);
}
 
void insert (int xP) {
    for (block &cur : blocks)
        if (cur.last() >= xP) return cur.insert(xP), void();
    blocks[(int)blocks.size() - 1].insert(xP);
}
 
void remove (int xP) {
    for (block &cur : blocks)
        if (cur.last() >= xP) return cur.remove(xP), void();
}
 
int query() {
    int curPos = -1, ans = 0;
    for (block &cur : blocks) {
        int newPos, step; tie(newPos, step) = cur.batchJump(curPos);
        curPos = newPos, ans += step;
    }
    return ans;
}
 
void init (int _n, int _L, int X[]) {
    n = _n, L = _L;
    vector<int> vec(n);
    for (int i = 0; i < n; i++) vec[i] = save[i] = X[i];
    build(vec);
}
 
int update (int i, int y) {
    if (queryCount && queryCount % resetCycle == 0) reBuild();
    queryCount++, remove(save[i]), insert(y), save[i] = y;
    return query();
}

Compilation message

elephants.cpp: In member function 'void block::refine()':
elephants.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |             if (iter == x.size()) jumpTo[i] = x[i] + L, step[i] = 1;
      |                 ~~~~~^~~~~~~~~~~
elephants.cpp: In member function 'pii block::batchJump(int)':
elephants.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         if (pos == x.size()) return {start, 0};
      |             ~~~~^~~~~~~~~~~
elephants.cpp: In function 'void build(const std::vector<int>&)':
elephants.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i = 0; i < x.size(); i += blockSize) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 2 ms 2504 KB Output is correct
6 Correct 1 ms 2404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 2 ms 2504 KB Output is correct
6 Correct 1 ms 2404 KB Output is correct
7 Correct 204 ms 3408 KB Output is correct
8 Correct 278 ms 4632 KB Output is correct
9 Correct 347 ms 4068 KB Output is correct
10 Correct 321 ms 4004 KB Output is correct
11 Correct 321 ms 2744 KB Output is correct
12 Correct 664 ms 6304 KB Output is correct
13 Correct 344 ms 3656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 2 ms 2504 KB Output is correct
6 Correct 1 ms 2404 KB Output is correct
7 Correct 204 ms 3408 KB Output is correct
8 Correct 278 ms 4632 KB Output is correct
9 Correct 347 ms 4068 KB Output is correct
10 Correct 321 ms 4004 KB Output is correct
11 Correct 321 ms 2744 KB Output is correct
12 Correct 664 ms 6304 KB Output is correct
13 Correct 344 ms 3656 KB Output is correct
14 Correct 325 ms 3564 KB Output is correct
15 Correct 380 ms 3396 KB Output is correct
16 Correct 1049 ms 5088 KB Output is correct
17 Correct 1188 ms 4124 KB Output is correct
18 Correct 1341 ms 6052 KB Output is correct
19 Correct 754 ms 5784 KB Output is correct
20 Correct 1283 ms 4612 KB Output is correct
21 Correct 1094 ms 6016 KB Output is correct
22 Correct 739 ms 4540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 2 ms 2504 KB Output is correct
6 Correct 1 ms 2404 KB Output is correct
7 Correct 204 ms 3408 KB Output is correct
8 Correct 278 ms 4632 KB Output is correct
9 Correct 347 ms 4068 KB Output is correct
10 Correct 321 ms 4004 KB Output is correct
11 Correct 321 ms 2744 KB Output is correct
12 Correct 664 ms 6304 KB Output is correct
13 Correct 344 ms 3656 KB Output is correct
14 Correct 325 ms 3564 KB Output is correct
15 Correct 380 ms 3396 KB Output is correct
16 Correct 1049 ms 5088 KB Output is correct
17 Correct 1188 ms 4124 KB Output is correct
18 Correct 1341 ms 6052 KB Output is correct
19 Correct 754 ms 5784 KB Output is correct
20 Correct 1283 ms 4612 KB Output is correct
21 Correct 1094 ms 6016 KB Output is correct
22 Correct 739 ms 4540 KB Output is correct
23 Correct 3076 ms 11764 KB Output is correct
24 Correct 3376 ms 6896 KB Output is correct
25 Correct 2647 ms 11604 KB Output is correct
26 Correct 2897 ms 8792 KB Output is correct
27 Correct 2827 ms 6904 KB Output is correct
28 Correct 1034 ms 2388 KB Output is correct
29 Correct 924 ms 2428 KB Output is correct
30 Correct 1038 ms 4204 KB Output is correct
31 Correct 961 ms 4476 KB Output is correct
32 Correct 2585 ms 6916 KB Output is correct
33 Correct 2557 ms 8512 KB Output is correct
34 Correct 2587 ms 9476 KB Output is correct
35 Correct 2657 ms 9744 KB Output is correct
36 Correct 2472 ms 8804 KB Output is correct
37 Correct 3101 ms 7552 KB Output is correct
38 Correct 2687 ms 8568 KB Output is correct
39 Correct 2586 ms 8652 KB Output is correct
40 Correct 2699 ms 6920 KB Output is correct
41 Correct 4166 ms 10332 KB Output is correct
42 Correct 4383 ms 7760 KB Output is correct