QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#228353 | #7642. Integer Half-Sum | ucup-team896# | AC ✓ | 0ms | 3812kb | C++23 | 7.7kb | 2023-10-28 13:23:55 | 2023-10-28 13:23:56 |
Judging History
answer
/*
* @Author: cmk666
* @Created time: 2023-10-28 13:19:55
* @Last Modified time: 2023-10-28 13:23:40
*/
#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), pc(32), 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;
int l, r, nw, qwq; multiset < int > st[2];
int main()
{
read(l, r);
For(i, l, r) st[i & 1].insert(i);
while ( (int)st[0].size() > 1 || (int)st[1].size() > 1 )
{
if ( (int)st[0].size() < 2 ) nw = 1;
else if ( (int)st[1].size() < 2 ) nw = 0;
else nw = *st[0].begin() + *++st[0].begin() > *st[1].begin() + *++st[1].begin();
qwq = ( *st[nw].begin() + *++st[nw].begin() ) >> 1;
st[nw].erase(st[nw].begin()), st[nw].erase(st[nw].begin()), st[qwq & 1].insert(qwq);
}
if ( st[0].size() && st[1].size() ) return println("-1"s), 0;
return println(*st[st[0].empty()].begin()), 0;
}
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
2 4
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
1 2
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
100 100
output:
100
result:
ok 1 number(s): "100"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
99 100
output:
-1
result:
ok 1 number(s): "-1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3468kb
input:
3 3
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
2 3
output:
-1
result:
ok 1 number(s): "-1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
1 3
output:
2
result:
ok 1 number(s): "2"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
2 5
output:
4
result:
ok 1 number(s): "4"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
3 7
output:
6
result:
ok 1 number(s): "6"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
3 8
output:
7
result:
ok 1 number(s): "7"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
4 10
output:
9
result:
ok 1 number(s): "9"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
35 37
output:
36
result:
ok 1 number(s): "36"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
43 46
output:
45
result:
ok 1 number(s): "45"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
82 86
output:
85
result:
ok 1 number(s): "85"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
55 60
output:
59
result:
ok 1 number(s): "59"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
25 31
output:
30
result:
ok 1 number(s): "30"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
37 44
output:
43
result:
ok 1 number(s): "43"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
75 83
output:
82
result:
ok 1 number(s): "82"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
74 83
output:
82
result:
ok 1 number(s): "82"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
88 98
output:
97
result:
ok 1 number(s): "97"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
75 86
output:
85
result:
ok 1 number(s): "85"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
1 100
output:
99
result:
ok 1 number(s): "99"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1 50
output:
49
result:
ok 1 number(s): "49"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
50 100
output:
99
result:
ok 1 number(s): "99"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
7 35
output:
34
result:
ok 1 number(s): "34"
Test #27:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
87 95
output:
94
result:
ok 1 number(s): "94"
Test #28:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
11 30
output:
29
result:
ok 1 number(s): "29"
Test #29:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
47 69
output:
68
result:
ok 1 number(s): "68"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
11 48
output:
47
result:
ok 1 number(s): "47"
Test #31:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
71 85
output:
84
result:
ok 1 number(s): "84"
Test #32:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
84 89
output:
88
result:
ok 1 number(s): "88"
Test #33:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
22 56
output:
55
result:
ok 1 number(s): "55"
Test #34:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
2 72
output:
71
result:
ok 1 number(s): "71"
Test #35:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
18 55
output:
54
result:
ok 1 number(s): "54"
Test #36:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
4 11
output:
10
result:
ok 1 number(s): "10"
Test #37:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
42 59
output:
58
result:
ok 1 number(s): "58"
Test #38:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
52 79
output:
78
result:
ok 1 number(s): "78"
Test #39:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
11 48
output:
47
result:
ok 1 number(s): "47"
Test #40:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
4 51
output:
50
result:
ok 1 number(s): "50"
Test #41:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
3 60
output:
59
result:
ok 1 number(s): "59"
Test #42:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
21 88
output:
87
result:
ok 1 number(s): "87"
Test #43:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
17 94
output:
93
result:
ok 1 number(s): "93"
Test #44:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
11 98
output:
97
result:
ok 1 number(s): "97"
Test #45:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
2 99
output:
98
result:
ok 1 number(s): "98"
Extra Test:
score: 0
Extra Test Passed