QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#157998 | #7105. Pixel Art | ucup-team896# | AC ✓ | 252ms | 24000kb | C++23 | 10.5kb | 2023-09-02 16:06:45 | 2023-09-04 04:30:29 |
Judging History
answer
/*
* @Author: cmk666
* @Created time: 2023-09-02 14:49:39
* @Last Modified time: 2023-09-02 16:06:01
*/
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#ifdef LOCAL
#include"debug.h"
#else
#define D(...) ((void)0)
#endif
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
namespace FastIO
{
// ------------------------------
// #define IN_HAS_NEG
// #define OUT_HAS_NEG
// #define CHK_EOF
// #define DISABLE_MMAP
// ------------------------------
#if __cplusplus < 201400
#error Please use C++14 or higher.
#endif
#if __cplusplus > 201700
#define INLINE_V inline
#else
#define INLINE_V
#endif
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifndef DISABLE_MMAP
#include<sys/mman.h>
#endif
#ifdef LOCAL
inline char gc() { return getchar(); }
inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
INLINE_V constexpr int _READ_SIZE = 1 << 18;
INLINE_V static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr, *_read_ptr_end = nullptr;
inline char gc()
{
if ( __builtin_expect(_read_ptr == _read_ptr_end, false) )
{
_read_ptr = _read_buffer;
_read_ptr_end = _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin);
#ifdef CHK_EOF
if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) return EOF;
#endif
}
return *_read_ptr++;
}
#else
INLINE_V static const char *_read_ptr = (const char *)mmap(nullptr, INT_MAX, 1, 2, 0, 0);
inline char gc() { return *_read_ptr++; }
#endif
INLINE_V constexpr int _WRITE_SIZE = 1 << 18;
INLINE_V static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer;
inline void pc(char c)
{
*_write_ptr++ = c;
if ( __builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false) )
{
fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
_write_ptr = _write_buffer;
}
}
INLINE_V struct _auto_flush
{
inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); }
} _auto_flush;
#endif
#ifdef CHK_EOF
inline constexpr bool _isdigit(char c) { return ( c & 16 ) && c != EOF; }
inline constexpr bool _isgraph(char c) { return c > 32 && c != EOF; }
#else
inline constexpr bool _isdigit(char c) { return c & 16; }
inline constexpr bool _isgraph(char c) { return c > 32; }
#endif
template < class T >
INLINE_V constexpr bool _is_integer = numeric_limits < T >::is_integer;
template < class T >
INLINE_V constexpr bool _is_signed = numeric_limits < T >::is_signed;
template < class T >
INLINE_V constexpr bool _is_unsigned = _is_integer < T > && !_is_signed < T >;
template <> INLINE_V constexpr bool _is_integer < __int128 > = true;
template <> INLINE_V constexpr bool _is_integer < __uint128_t > = true;
template <> INLINE_V constexpr bool _is_signed < __int128 > = true;
template <> INLINE_V constexpr bool _is_unsigned < __uint128_t > = true;
#undef INLINE_V
inline void read(char &c) { do c = gc(); while ( !_isgraph(c) ); }
inline void read_cstr(char *s)
{
char c = gc(); while ( !_isgraph(c) ) c = gc();
while ( _isgraph(c) ) *s++ = c, c = gc();
*s = 0;
}
inline void read(string &s)
{
char c = gc(); s.clear(); while ( !_isgraph(c) ) c = gc();
while ( _isgraph(c) ) s.push_back(c), c = gc();
}
#ifdef IN_HAS_NEG
template < class T, enable_if_t < _is_signed < T >, int > = 0 >
inline void read(T &x)
{
char c = gc(); bool f = true; x = 0;
while ( !_isdigit(c) ) { if ( c == 45 ) f = false; c = gc(); }
if ( f ) while ( _isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
else while ( _isdigit(c) ) x = x * 10 - ( c & 15 ), c = gc();
}
template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
#else
template < class T, enable_if_t < _is_integer < T >, int > = 0 >
#endif
inline void read(T &x)
{
char c = gc(); while ( !_isdigit(c) ) c = gc();
x = 0; while ( _isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
}
inline void write(char c) { pc(c); }
inline void write_cstr(const char *s) { while ( *s ) pc(*s++); }
inline void write(const string &s) { for ( char c : s ) pc(c); }
#ifdef OUT_HAS_NEG
template < class T, enable_if_t < _is_signed < T >, int > = 0 >
inline void write(T x)
{
char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0;
if ( x >= 0 ) do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x );
else { pc(45); do buffer[digits++] = -( x % 10 ) | 48, x /= 10; while ( x ); }
while ( digits ) pc(buffer[--digits]);
}
template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
#else
template < class T, enable_if_t < _is_integer < T >, int > = 0 >
#endif
inline void write(T x)
{
char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0;
do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x );
while ( digits ) pc(buffer[--digits]);
}
template < int N > struct _tuple_io_helper
{
template < class ...T >
static inline void _read(tuple < T... > &x)
{ _tuple_io_helper < N - 1 >::_read(x), read(get < N - 1 > (x)); }
template < class ...T >
static inline void _write(const tuple < T... > &x)
{ _tuple_io_helper < N - 1 >::_write(x), pc(32), write(get < N - 1 > (x)); }
};
template <> struct _tuple_io_helper < 1 >
{
template < class ...T >
static inline void _read(tuple < T... > &x) { read(get < 0 > (x)); }
template < class ...T >
static inline void _write(const tuple < T... > &x) { write(get < 0 > (x)); }
};
template < class ...T >
inline void read(tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_read(x); }
template < class ...T >
inline void write(const tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_write(x); }
template < class T1, class T2 >
inline void read(pair < T1, T2 > &x) { read(x.first), read(x.second); }
template < class T1, class T2 >
inline void write(const pair < T1, T2 > &x) { write(x.first), pc(32), write(x.second); }
template < class T1, class ...T2 >
inline void read(T1 &x, T2 &...y) { read(x), read(y...); }
template < class ...T >
inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); }
template < class T1, class ...T2 >
inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); }
template < class ...T >
inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); }
template < class T >
inline void print(const T &x) { write(x); }
inline void print_cstr(const char *x) { write_cstr(x); }
template < class T1, class ...T2 >
inline void print(const T1 &x, const T2 &...y) { print(x), pc(32), print(y...); }
template < class ...T >
inline void print_cstr(const char *x, const T *...y) { print_cstr(x), print_cstr(y...); }
inline void println() { pc(10); }
inline void println_cstr() { pc(10); }
template < class ...T >
inline void println(const T &...x) { print(x...), pc(10); }
template < class ...T >
inline void println_cstr(const T *...x) { print_cstr(x...), pc(10); }
}
using namespace FastIO;
namespace DSU
{
int fa[100009], sz[100009];
inline void init(int x) { For(i, 1, x) fa[i] = i, sz[i] = 1; }
inline int fat(int x) { return x == fa[x] ? x : fa[x] = fat(fa[x]); }
inline bool issame(int x, int y) { return fat(x) == fat(y); }
inline void union_(int x, int y)
{
if ( ( x = fat(x) ) == ( y = fat(y) ) ) return;
if ( sz[x] > sz[y] ) sz[x] += sz[y], fa[y] = x;
else sz[y] += sz[x], fa[x] = y;
}
}
using pii = pair < int, int >; using a4 = array < int, 4 >;
#define fi first
#define se second
int n, m, k, ans2, al, bl, r1[100009], c1[100009], r2[100009], c2[100009], rp, cp, rq, cq, cc;
ll ans1; vector < int > rm[100009]; a4 a[100009], b[100009]; set < pii > strp, strq, stcp, stcq;
inline bool cmp(const a4 &x, const a4 &y) { return x[0] != y[0] ? x[0] < y[0] : x[1] < y[1]; };
inline void mrg(int u, int v) { if ( !DSU::issame(u, v) ) DSU::union_(u, v), ans2--; }
#define mrg(_1, _2) D("mrg", _1, _2), mrg(_1, _2)
inline void work()
{
read(n, m, k), DSU::init(k), ans1 = ans2 = al = bl = cc = 0;
strq.clear(), stcq.clear(), strp.clear(), stcp.clear();
For(i, 1, n + 1) rm[i].clear();
For(i, 1, k)
{
read(r1[i], c1[i], r2[i], c2[i]);
if ( r1[i] == r2[i] ) a[++al] = { r1[i], c1[i], c2[i] - c1[i] + 1, i };
else b[++bl] = { r1[i], c1[i], r2[i] - r1[i] + 1, i };
}
sort(a + 1, a + al + 1, cmp), sort(b + 1, b + bl + 1, cmp), rp = cp = 1;
For(i, 1, n)
{
rq = rp, cq = cp;
for ( ; rp <= al ; rp++ )
{
auto [x, y, len, id] = a[rp]; int z = y + len - 1;
if ( x != i ) break;
ans1 += len, ans2++;
auto it = stcq.lower_bound(pii(y, 0));
for ( ; it != stcq.end() && it -> fi <= z ; it++ ) mrg(id, it -> se);
it = strq.lower_bound(pii(y, 0));
if ( it != strq.begin() ) it--;
for ( ; it != strq.end() && c2[it -> se] < y ; it++ );
for ( ; it != strq.end() && c1[it -> se] <= z ; it++ ) mrg(id, it -> se);
strp.emplace(y, id);
}
for ( ; cp <= bl ; cp++ )
{
auto [x, y, len, id] = b[cp];
if ( x != i ) break;
ans2++;
auto it = stcq.lower_bound(pii(y, 0));
if ( it != stcq.end() && it -> fi == y ) mrg(id, it -> se);
it = strq.lower_bound(pii(y + 1, 0));
if ( it != strq.begin() ) it--;
if ( it != strq.end() && c1[it -> se] <= y && c2[it -> se] >= y ) mrg(id, it -> se);
stcp.emplace(y, id), rm[x + len].push_back(id);
}
strq = move(strp), strp.clear();
for ( int id : rm[i] ) stcq.erase(pii(c1[id], id)), cc--;
for ( pii p : stcp ) stcq.emplace(p), cc++;
stcp.clear(), ans1 += cc;
for ( ; rq < rp ; rq++ )
{
auto [x, y, len, id] = a[rq];
auto it = stcq.lower_bound(pii(c2[id] + 1, 0));
if ( it != stcq.end() && it -> fi == c2[id] + 1 ) mrg(id, it -> se);
if ( it != stcq.begin() ) it--;
if ( it != stcq.end() && it -> fi == c1[id] - 1 ) mrg(id, it -> se);
it = strq.lower_bound(pii(c2[id] + 1, 0));
if ( it != strq.end() && it -> fi == c2[id] + 1 ) mrg(id, it -> se);
}
for ( ; cq < cp ; cq++ )
{
auto [x, y, len, id] = b[cq];
auto it = stcq.lower_bound(pii(y + 1, 0));
if ( it != stcq.end() && it -> fi == y + 1 ) mrg(id, it -> se);
it = stcq.lower_bound(pii(y - 1, 0));
if ( it != stcq.end() && it -> fi == y - 1 ) mrg(id, it -> se);
}
println(ans1, ans2);
}
}
int main() { int t; read(t); For(tt, 1, t) work(); return 0; }
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9764kb
input:
3 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3
output:
2 1 5 2 3 1 6 1 3 1 4 1 6 2
result:
ok 7 lines
Test #2:
score: 0
Accepted
time: 252ms
memory: 24000kb
input:
2130 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3 3 100 51 1 2 2 2 1 4 2 4 1 6 2 6 1 8 2 8 1 10 2 10 1 12 2 12 1 14 2 14 1 16 2 16 1 18 2 18 1 20 2 20 1 22 2 22 1 24 2 24 1 26 2 26 1 28 2 28 1 30 2 30 1 32 2 32 1 34 2 34 1 36 2 36 1 38 2 38 1 40 2 40 1 42 2 42 1 44 2 44 ...
output:
2 1 5 2 3 1 6 1 3 1 4 1 6 2 50 50 100 50 200 1 50 50 150 1 200 1 2 1 4 1 6 1 8 1 10 1 12 1 14 1 16 1 18 1 20 1 22 1 24 1 26 1 28 1 30 1 32 1 34 1 36 1 38 1 40 1 42 1 44 1 46 1 48 1 50 1 52 1 54 1 56 1 58 1 60 1 62 1 64 1 66 1 68 1 70 1 72 1 74 1 76 1 78 1 80 1 82 1 84 1 86 1 88 1 90 1 92 1 94 1 96 1...
result:
ok 355756 lines
Extra Test:
score: 0
Extra Test Passed