답안 #1032404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032404 2024-07-23T17:03:23 Z shmax Rectangles (IOI19_rect) C++17
37 / 100
5000 ms 882452 KB
#include "rect.h"
#include <bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2")

using namespace std;
using i32 = int;
//#define int long long
#define len(x) (int)(x.size())
#define inf 1000'000'000'000'000'000LL
#define all(x) x.begin(), x.end()
#define low_bit(x) (x & (-x))

template<typename T>
using vec = vector<T>;

const int maxM = 701;

template<typename it>
struct SparseTable {

    using T = typename remove_reference<decltype(*declval<it>())>::type;
    vector<vector<T>> t;
    function<T(T, T)> f;
    vector<int> log;

    SparseTable() = default;

    SparseTable(it first, it last, function<T(T, T)> op) : t(1), f(op) {
        int n = distance(first, last);
        t.assign(32 - __builtin_clz(n), vector<T>(n));
        t[0].assign(first, last);
        //       calc log
        log.resize(n + 1);
        for (int i = 2; i <= n; i++)
            log[i] = log[i / 2] + 1;

        for (int i = 1; i < t.size(); i++)
            for (int j = 0; j < n - (1 << i) + 1; j++)
                t[i][j] = f(t[i - 1][j], t[i - 1][j + (1 << (i - 1))]);
    }

    // returns f(a[l..r]) in O(1) time
    T get(int l, int r) {
        int h = log[r - l + 1];
        return f(t[h][l], t[h][r - (1 << h) + 1]);
    }
};

long long count_rectangles(std::vector<std::vector<i32>> a) {
    int n = len(a);
    int m = len(a[0]);
    long long ans = 0;
    vec<vec<bitset<maxM>>> b(n, vec<bitset<maxM>>(m));
    for (int i = 1; i < n - 1; i++) {
        for (int j = 1; j < m - 1; j++) {
            b[i][j].reset();
            int mx = a[i][j];
            for (int l = i; l < n - 1; l++) {
                mx = max(mx, a[l][j]);
                if (mx >= min(a[i - 1][j], a[l + 1][j])) continue;
                b[i][j][l] = true;
            }

        }
    }

    vec<vec<bitset<maxM>>> good(m, vec<bitset<maxM>>(m));

    vec<SparseTable<vec<int>::iterator>> maxVal;
    for (int i = 0; i < n; i++) {
        maxVal.emplace_back(all(a[i]), [](int a, int b) {
            return max(a, b);
        });
    }
    for (int l = 1; l < m - 1; l++) {
        for (int r = l; r < m - 1; r++) {
            for (int i = 0; i < n; i++) {
                good[l][r][i] = maxVal[i].get(l, r) < min(a[i][l - 1], a[i][r + 1]);
            }
        }
    }
    vec<vec<vec<short>>> lowest(m, vec<vec<short>>(m, vec<short>(n, 0)));
    for (int l = 1; l < m - 1; l++) {
        for (int r = l; r < m - 1; r++) {
            for (int i = n - 2; i >= 1; i--) {
                if (!good[l][r][i]) continue;
                lowest[l][r][i] = lowest[l][r][i + 1] + 1;
            }
        }
    }
    for (int i = 1; i < n - 1; i++) {
        for (int j = 1; j < m - 1; j++) {
            if (a[i][j] >= a[i - 1][j]) continue;
            if (a[i][j] >= a[i][j - 1]) continue;
            for (int k = j; k < m - 1; k++) {
                b[i][j] &= b[i][k];
                if (b[i][j].count() == 0) break;
                if (lowest[j][k][i] == 0) continue;
                ans += (b[i][j] << (maxM - i - lowest[j][k][i])).count();
            }
        }
    }

    return ans;
}

Compilation message

rect.cpp: In instantiation of 'SparseTable<it>::SparseTable(it, it, std::function<typename std::remove_reference<decltype (* declval<it>())>::type(typename std::remove_reference<decltype (* declval<it>())>::type, typename std::remove_reference<decltype (* declval<it>())>::type)>) [with it = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::remove_reference<decltype (* declval<it>())>::type = int]':
/usr/include/c++/10/ext/new_allocator.h:150:4:   required from 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = SparseTable<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >; _Args = {__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, count_rectangles(std::vector<std::vector<int> >)::<lambda(int, int)>}; _Tp = SparseTable<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >]'
/usr/include/c++/10/bits/alloc_traits.h:512:17:   required from 'static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = SparseTable<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >; _Args = {__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, count_rectangles(std::vector<std::vector<int> >)::<lambda(int, int)>}; _Tp = SparseTable<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<SparseTable<__gnu_cxx::__normal_iterator<int*, std::vector<int> > > >]'
/usr/include/c++/10/bits/vector.tcc:115:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, count_rectangles(std::vector<std::vector<int> >)::<lambda(int, int)>}; _Tp = SparseTable<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >; _Alloc = std::allocator<SparseTable<__gnu_cxx::__normal_iterator<int*, std::vector<int> > > >; std::vector<_Tp, _Alloc>::reference = SparseTable<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >&]'
rect.cpp:76:10:   required from here
rect.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int i = 1; i < t.size(); i++)
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 6 ms 2908 KB Output is correct
23 Correct 5 ms 2908 KB Output is correct
24 Correct 6 ms 2904 KB Output is correct
25 Correct 5 ms 2904 KB Output is correct
26 Correct 4 ms 2908 KB Output is correct
27 Correct 4 ms 2908 KB Output is correct
28 Correct 4 ms 2908 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 6 ms 2908 KB Output is correct
18 Correct 5 ms 2908 KB Output is correct
19 Correct 6 ms 2904 KB Output is correct
20 Correct 5 ms 2904 KB Output is correct
21 Correct 4 ms 2908 KB Output is correct
22 Correct 4 ms 2908 KB Output is correct
23 Correct 4 ms 2908 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 77 ms 26196 KB Output is correct
31 Correct 80 ms 26196 KB Output is correct
32 Correct 84 ms 26456 KB Output is correct
33 Correct 48 ms 26200 KB Output is correct
34 Correct 48 ms 26196 KB Output is correct
35 Correct 46 ms 26448 KB Output is correct
36 Correct 51 ms 26232 KB Output is correct
37 Correct 46 ms 25936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 6 ms 2908 KB Output is correct
18 Correct 5 ms 2908 KB Output is correct
19 Correct 6 ms 2904 KB Output is correct
20 Correct 5 ms 2904 KB Output is correct
21 Correct 4 ms 2908 KB Output is correct
22 Correct 4 ms 2908 KB Output is correct
23 Correct 4 ms 2908 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 77 ms 26196 KB Output is correct
26 Correct 80 ms 26196 KB Output is correct
27 Correct 84 ms 26456 KB Output is correct
28 Correct 48 ms 26200 KB Output is correct
29 Correct 48 ms 26196 KB Output is correct
30 Correct 46 ms 26448 KB Output is correct
31 Correct 51 ms 26232 KB Output is correct
32 Correct 46 ms 25936 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 604 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 2812 ms 797548 KB Output is correct
39 Correct 2995 ms 797548 KB Output is correct
40 Correct 2803 ms 797696 KB Output is correct
41 Correct 2826 ms 797552 KB Output is correct
42 Correct 4403 ms 797520 KB Output is correct
43 Correct 4481 ms 795472 KB Output is correct
44 Execution timed out 5022 ms 797552 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 602 ms 882436 KB Output is correct
2 Correct 454 ms 636640 KB Output is correct
3 Correct 587 ms 882208 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 549 ms 882264 KB Output is correct
6 Correct 568 ms 882416 KB Output is correct
7 Correct 606 ms 882380 KB Output is correct
8 Correct 561 ms 882452 KB Output is correct
9 Correct 586 ms 882348 KB Output is correct
10 Correct 522 ms 881736 KB Output is correct
11 Correct 531 ms 882028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Execution timed out 5116 ms 880544 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 6 ms 2908 KB Output is correct
18 Correct 5 ms 2908 KB Output is correct
19 Correct 6 ms 2904 KB Output is correct
20 Correct 5 ms 2904 KB Output is correct
21 Correct 4 ms 2908 KB Output is correct
22 Correct 4 ms 2908 KB Output is correct
23 Correct 4 ms 2908 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 77 ms 26196 KB Output is correct
26 Correct 80 ms 26196 KB Output is correct
27 Correct 84 ms 26456 KB Output is correct
28 Correct 48 ms 26200 KB Output is correct
29 Correct 48 ms 26196 KB Output is correct
30 Correct 46 ms 26448 KB Output is correct
31 Correct 51 ms 26232 KB Output is correct
32 Correct 46 ms 25936 KB Output is correct
33 Correct 2812 ms 797548 KB Output is correct
34 Correct 2995 ms 797548 KB Output is correct
35 Correct 2803 ms 797696 KB Output is correct
36 Correct 2826 ms 797552 KB Output is correct
37 Correct 4403 ms 797520 KB Output is correct
38 Correct 4481 ms 795472 KB Output is correct
39 Execution timed out 5022 ms 797552 KB Time limit exceeded
40 Halted 0 ms 0 KB -