답안 #1065493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065493 2024-08-19T08:25:24 Z ewirlan Rectangles (IOI19_rect) C++17
13 / 100
1669 ms 602608 KB
//
#ifndef __SIZEOF_INT128__
  #define __SIZEOF_INT128__
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template <typename T> using oset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i, p, k) for(int i(p); i < (k); ++i)
#define per(i, p, k) for(int i(p); i > (k); --i)
#define sz(x) (int)(x).size()
#define sc static_cast
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef __int128_t lll;
//#define int ll
template <typename T = int> using par = std::pair <T, T>;
#define fi first
#define se second
#define test int _number_of_tests(in()); while(_number_of_tests--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb emplace_back
struct Timer {
    string name{""};
    time_point<high_resolution_clock> end, start{high_resolution_clock::now()};
    duration<float, std::milli> dur;
    Timer() = default;
    Timer(string nm): name(nm) {}
    ~Timer() {
        end = high_resolution_clock::now(); dur= end - start;
        cout << "@" << name << "> " << dur.count() << " ms" << '\n';
    }
};
template <typename T = int> inline T in()
{
    static T x;
    std::cin >> x;
    return x;
}
std::string yn(bool b)
{
    if(b) return "YES\n";
    else return "NO\n";
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par);
template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek)
{
    for(const auto& i : wek)out << i << ' ';
    return out;
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par)
{
    out << '{'<<par.first<<", "<<par.second<<"}";
    return out;
}
#define show(x) cerr << #x << " = " << x << '\n';
template <typename T>
vector <int> ostw(T b, T e, bool r)
{
    vector <int> o;
    vector <pair <int, int>> k{{1e9, -1}};
    int j(0);
    for(auto i(b); i != e; ++i){
        while(k.back().first < *i || (k.back().first == *i && !r))k.pop_back();
        o.pb(k.back().second);
        k.pb(*i, j++);
    }
    return o;
}
constexpr int maxn = 2503, pol = 1<<12;
array <array <int, maxn>, maxn> r, l, u, d;
array <array <int, pol*2>, maxn> mr, ml, mu, md;
template <typename T>
void trurev(T b, T e, int n)
{
    reverse(b, e);
    for(auto i(b); i != e; ++i)if(*i != -1)*i = n-1-*i;
}
struct rect{int x1, y1, x2, y2;};
bool operator<(rect a, rect b)
{
    if(a.x1 != b.x1)return a.x1 < b.x1;
    if(a.y1 != b.y1)return a.y1 < b.y1;
    if(a.x2 != b.x2)return a.x2 < b.x2;
    return a.y2 < b.y2;
}
int maks(const array <int, pol*2>& tr, int a, int b)
{
    a += pol; b += pol;
    int s(-1e9);
    while(a+1 != b){
        if(a % 2 == 0)s = max(s, tr[a+1]);
        if(b % 2 == 1)s = max(s, tr[b-1]);
        a /= 2;
        b /= 2;
    }
    return s;
}
int mini(const array <int, pol*2>& tr, int a, int b)
{
    a += pol; b += pol;
    int s(1e9);
    while(a+1 != b){
        if(a % 2 == 0)s = min(s, tr[a+1]);
        if(b % 2 == 1)s = min(s, tr[b-1]);
        a /= 2;
        b /= 2;
    }
    return s;
}
ll count_rectangles(vector <vector <int>> a)
{
    int n(sz(a)), m(sz(a[0]));
    rep(i, 0, n){
        vector <int> dl(ostw(all(a[i]), 0)), dr(ostw(rall(a[i]), 0)), dml(ostw(all(a[i]), 1)), dmr(ostw(rall(a[i]), 1));
        trurev(all(dr), m);
        trurev(all(dmr), m);
        rep(j, 0, m)l[i][j] = dl[j];
        rep(j, 0, m)r[i][j] = dr[j];
        rep(j, 0, m)ml[j][i+pol] = dml[j];
        rep(j, 0, m)mr[j][i+pol] = dmr[j] == -1 ? n+1 : dmr[j];
    }
    rep(i, 0, m){
        vector <int> v(n);
        rep(j, 0, n)v[j] = a[j][i];
        vector <int> du(ostw(all(v), 0)), dd(ostw(rall(v), 0)), dmu(ostw(all(v), 1)), dmd(ostw(rall(v), 1));
        trurev(all(dd), n);
        trurev(all(dmd), n);
        rep(j, 0, n)u[j][i] = du[j];
        rep(j, 0, n)d[j][i] = dd[j];
        rep(j, 0, n)mu[j][i+pol] = dmu[j];
        rep(j, 0, n)md[j][i+pol] = dmd[j] == -1 ? n+1 : dmd[j];
    }
    rep(i, 0, n)per(j, pol-1, 0)mu[i][j] = max(mu[i][j*2], mu[i][j*2+1]);
    rep(i, 0, n)per(j, pol-1, 0)md[i][j] = min(md[i][j*2], md[i][j*2+1]);
    rep(i, 0, m)per(j, pol-1, 0)ml[i][j] = max(ml[i][j*2], ml[i][j*2+1]);
    rep(i, 0, m)per(j, pol-1, 0)mr[i][j] = min(mr[i][j*2], mr[i][j*2+1]);
    set <rect> S;
    rep(i, 0, n)rep(j, 0, m)if(~l[i][j] && ~u[i][j] && ~r[i][j] && ~d[i][j])S.insert({u[i][j], l[i][j], d[i][j], r[i][j]});
    int o(0);
    for(auto [x1, y1, x2, y2]: S){
        // cerr << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << " =/= "<< ' ' << maks(mu[x2], y1, y2) << ' ' << maks(ml[y2], x1, x2) << ' ' << mini(mr[y1], x1, x2) << ' ' << mini(md[x1], y1, y2) << '\n';
        o += mini(md[x1], y1, y2) >= x2 && mini(mr[y1], x1, x2) >= y2 && maks(mu[x2], y1, y2) <= x1 && maks(ml[y2], x1, x2) <= y1;
    }
    return o;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 2 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Incorrect 2 ms 16732 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 2 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Incorrect 2 ms 16732 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 2 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Incorrect 2 ms 16732 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 2 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Incorrect 2 ms 16732 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 116048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16816 KB Output is correct
2 Correct 825 ms 339104 KB Output is correct
3 Correct 1647 ms 600144 KB Output is correct
4 Correct 1669 ms 602608 KB Output is correct
5 Correct 1666 ms 602060 KB Output is correct
6 Correct 398 ms 277076 KB Output is correct
7 Correct 717 ms 431532 KB Output is correct
8 Correct 854 ms 444020 KB Output is correct
9 Correct 2 ms 14680 KB Output is correct
10 Correct 1 ms 14684 KB Output is correct
11 Correct 2 ms 16828 KB Output is correct
12 Correct 2 ms 16732 KB Output is correct
13 Correct 2 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 2 ms 16988 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Incorrect 2 ms 16732 KB Output isn't correct
9 Halted 0 ms 0 KB -