QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#882629#10042. Schedulingcmk666WA 40ms65444kbC++2313.1kb2025-02-05 10:04:162025-02-05 10:04:25

Judging History

This is the latest submission verdict.

  • [2025-02-05 10:04:25]
  • Judged
  • Verdict: WA
  • Time: 40ms
  • Memory: 65444kb
  • [2025-02-05 10:04:16]
  • Submitted

answer

/*  _              _     _                                             _       __      __      __   
   / \     _   _  | |_  | |__     ___    _ __   _    ___   _ __ ___   | | __  / /_    / /_    / /_  
  / _ \   | | | | | __| | '_ \   / _ \  | '__| (_)  / __| | '_ ` _ \  | |/ / | '_ \  | '_ \  | '_ \ 
 / ___ \  | |_| | | |_  | | | | | (_) | | |     _  | (__  | | | | | | |   <  | (_) | | (_) | | (_) |
/_/   \_\  \__,_|  \__| |_| |_|  \___/  |_|    (_)  \___| |_| |_| |_| |_|\_\  \___/   \___/   \___/ 
[Created Time:       2025-02-05 08:39:05]
[Last Modified Time: 2025-02-05 10:04:05] */
#ifdef LOCAL
#include<bits/stdc++.h>
#include"debug.h"
#else
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#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 USE_FastIO
// ------------------------------
// #define DISABLE_MMAP
// ------------------------------
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifdef LOCAL
	inline void _chk_i() {}
	inline char _gc_nochk() { return getchar(); }
	inline char _gc() { return getchar(); }
	inline void _chk_o() {}
	inline void _pc_nochk(char c) { putchar(c); }
	inline void _pc(char c) { putchar(c); }
	template < int n > inline void _pnc_nochk(const char *c) { for ( int i = 0 ; i < n ; i++ ) putchar(c[i]); }
#else
#ifdef DISABLE_MMAP
	inline constexpr int _READ_SIZE = 1 << 18; inline static char _read_buffer[_READ_SIZE + 40], *_read_ptr = nullptr, *_read_ptr_end = nullptr; static inline bool _eof = false;
	inline void _chk_i() { if ( __builtin_expect(!_eof, true) && __builtin_expect(_read_ptr_end - _read_ptr < 40, false) ) { int sz = _read_ptr_end - _read_ptr; if ( sz ) memcpy(_read_buffer, _read_ptr, sz); char *beg = _read_buffer + sz; _read_ptr = _read_buffer, _read_ptr_end = beg + fread(beg, 1, _READ_SIZE, stdin); if ( __builtin_expect(_read_ptr_end != beg + _READ_SIZE, false) ) _eof = true, *_read_ptr_end = EOF; } }
	inline char _gc_nochk() { return __builtin_expect(_eof && _read_ptr == _read_ptr_end, false) ? EOF : *_read_ptr++; }
	inline char _gc() { _chk_i(); return _gc_nochk(); }
#else
#include<sys/mman.h>
#include<sys/stat.h>
	inline static char *_read_ptr = (char *)mmap(nullptr, [] { struct stat s; return fstat(0, &s), s.st_size; } (), 1, 2, 0, 0);
	inline void _chk_i() {}
	inline char _gc_nochk() { return *_read_ptr++; }
	inline char _gc() { return *_read_ptr++; }
#endif
	inline constexpr int _WRITE_SIZE = 1 << 18; inline static char _write_buffer[_WRITE_SIZE + 40], *_write_ptr = _write_buffer;
	inline void _chk_o() { if ( __builtin_expect(_write_ptr - _write_buffer > _WRITE_SIZE, false) ) fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout), _write_ptr = _write_buffer; }
	inline void _pc_nochk(char c) { *_write_ptr++ = c; }
	inline void _pc(char c) { *_write_ptr++ = c, _chk_o(); }
	template < int n > inline void _pnc_nochk(const char *c) { memcpy(_write_ptr, c, n), _write_ptr += n; }
	inline struct _auto_flush { inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); } } _auto_flush;
#endif
#define println println_ // don't use C++23 std::println
	template < class T > inline constexpr bool _is_signed = numeric_limits < T >::is_signed;
	template < class T > inline constexpr bool _is_unsigned = numeric_limits < T >::is_integer && !_is_signed < T >;
#if __SIZEOF_LONG__ == 64
	template <> inline constexpr bool _is_signed < __int128 > = true;
	template <> inline constexpr bool _is_unsigned < __uint128_t > = true;
#endif
	inline bool _isgraph(char c) { return c >= 33; }
	inline bool _isdigit(char c) { return 48 <= c && c <= 57; } // or faster, remove c <= 57
	constexpr struct _table {
#ifndef LOCAL
	int i[65536];
#endif
	char o[40000]; constexpr _table() :
#ifndef LOCAL
	i{},
#endif
	o{} {
#ifndef LOCAL
	for ( int x = 0 ; x < 65536 ; x++ ) i[x] = -1; for ( int x = 0 ; x <= 9 ; x++ ) for ( int y = 0 ; y <= 9 ; y++ ) i[x + y * 256 + 12336] = x * 10 + y;
#endif
	for ( int x = 0 ; x < 10000 ; x++ ) for ( int y = 3, z = x ; ~y ; y-- ) o[x * 4 + y] = z % 10 + 48, z /= 10; } } _table;
	template < class T, int digit > inline constexpr T _pw10 = 10 * _pw10 < T, digit - 1 >;
	template < class T > inline constexpr T _pw10 < T, 0 > = 1;
	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(); }
	template < class T, bool neg >
#ifndef LOCAL
	__attribute__((no_sanitize("undefined")))
#endif
	inline void _read_int_suf(T &x) { _chk_i(); char c; while
#ifndef LOCAL
	( ~_table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)] ) if constexpr ( neg ) x = x * 100 - _table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)++]; else x = x * 100 + _table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)++]; if
#endif
	( _isdigit(c = _gc_nochk()) ) if constexpr ( neg ) x = x * 10 - ( c & 15 ); else x = x * 10 + ( c & 15 ); }
	template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void read(T &x) { char c; while ( !_isdigit(c = _gc()) ) if ( c == 45 ) { _read_int_suf < T, true >(x = -( _gc_nochk() & 15 )); return; } _read_int_suf < T, false >(x = c & 15); }
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > inline void read(T &x) { char c; while ( !_isdigit(c = _gc()) ); _read_int_suf < T, false >(x = c & 15); }
	inline void write(bool x) { _pc(x | 48); }
	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); }
	template < class T, bool neg, int digit > inline void _write_int_suf(T x) { if constexpr ( digit == 4 ) _pnc_nochk < 4 >(_table.o + ( neg ? -x : x ) * 4); else _write_int_suf < T, neg, digit / 2 >(x / _pw10 < T, digit / 2 >), _write_int_suf < T, neg, digit / 2 >(x % _pw10 < T, digit / 2 >); }
	template < class T, bool neg, int digit > inline void _write_int_pre(T x) { if constexpr ( digit <= 4 ) if ( digit >= 3 && ( neg ? x <= -100 : x >= 100 ) ) if ( digit >= 4 && ( neg ? x <= -1000 : x >= 1000 ) ) _pnc_nochk < 4 >(_table.o + ( neg ? -x : x ) * 4); else _pnc_nochk < 3 >(_table.o + ( neg ? -x : x ) * 4 + 1); else if ( digit >= 2 && ( neg ? x <= -10 : x >= 10 ) ) _pnc_nochk < 2 >(_table.o + ( neg ? -x : x ) * 4 + 2); else _pc_nochk(( neg ? -x : x ) | 48); else { constexpr int cur = 1 << __lg(digit - 1); if ( neg ? x <= -_pw10 < T, cur > : x >= _pw10 < T, cur > ) _write_int_pre < T, neg, digit - cur >(x / _pw10 < T, cur >), _write_int_suf < T, neg, cur >(x % _pw10 < T, cur >); else _write_int_pre < T, neg, cur >(x); } }
	template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void write(T x) { if ( x >= 0 ) _write_int_pre < T, false, numeric_limits < T >::digits10 + 1 >(x); else _pc_nochk(45), _write_int_pre < T, true, numeric_limits < T >::digits10 + 1 >(x); _chk_o(); }
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > inline void write(T x) { _write_int_pre < T, false, numeric_limits < T >::digits10 + 1 >(x), _chk_o(); }
	template < size_t N, class ...T > inline void _read_tuple(tuple < T... > &x) { read(get < N >(x)); if constexpr ( N + 1 != sizeof...(T) ) _read_tuple < N + 1, T... >(x); }
	template < size_t N, class ...T > inline void _write_tuple(const tuple < T... > &x) { write(get < N >(x)); if constexpr ( N + 1 != sizeof...(T) ) _pc(32), _write_tuple < N + 1, T... >(x); }
	template < class ...T > inline void read(tuple < T... > &x) { _read_tuple < 0, T... >(x); }
	template < class ...T > inline void write(const tuple < T... > &x) { _write_tuple < 0, T... >(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 T > inline auto read(T &x) -> decltype(x.read(), void()) { x.read(); }
	template < class T > inline auto write(const T &x) -> decltype(x.write(), void()) { x.write(); }
	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) { write(x), _pc(32), print(y...); }
	template < class ...T > inline void print_cstr(const char *x, const T *...y) { write_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 FastIO::read, FastIO::read_cstr, FastIO::write, FastIO::write_cstr, FastIO::println, FastIO::println_cstr;
constexpr int inf = numeric_limits < int >::max() >> 1;
namespace ST
{
	struct node
	{
		pair < int, int > v; int lz;
		inline void apply(int x) { v.first += x, lz += x; }
	}	t[600009 << 2];
	inline int lc(int p) { return p << 1; }
	inline int rc(int p) { return p << 1 | 1; }
	inline int md(int l, int r) { return ( l + r ) >> 1; }
	inline void pu(int p) { t[p].v = min(t[lc(p)].v, t[rc(p)].v); }
	inline void pd(int p) { if ( t[p].lz ) t[lc(p)].apply(t[p].lz), t[rc(p)].apply(t[p].lz), t[p].lz = 0; }
	inline void build(int p, int l, int r, auto &&f)
	{
		t[p].lz = 0;
		if ( l == r ) t[p].v = pair(f(l), l);
		else build(lc(p), l, md(l, r), f), build(rc(p), md(l, r) + 1, r, f), pu(p);
	}
	inline void add(int p, int l, int r, int lp, int rp, int v)
	{
		if ( l > rp || r < lp ) return;
		if ( lp <= l && r <= rp ) { t[p].apply(v); return; }
		pd(p), add(lc(p), l, md(l, r), lp, rp, v), add(rc(p), md(l, r) + 1, r, lp, rp, v), pu(p);
	}
	inline pair < int, int > qry(int p, int l, int r, int lp, int rp)
	{
		if ( l > rp || r < lp ) return pair(inf, inf);
		if ( lp <= l && r <= rp ) return t[p].v;
		return pd(p), min(qry(lc(p), l, md(l, r), lp, rp), qry(rc(p), md(l, r) + 1, r, lp, rp));
	}
}
int n, l[200009], r[200009], lp, rp, num[600009], len, f[600009], o[600009], ol, q[600009], ql, p;
bool flg, b[600009]; int fa[600009], ans[200009];
priority_queue < int, vector < int >, greater < int > > pq; basic_string < int > buc[600009];
inline int fat(int x) { return x == fa[x] ? x : fa[x] = fat(fa[x]); }
inline void work()
{
	read(n), len = 0;
	For(i, 1, n) read(l[i], r[i]), pq.push(l[i]);
	while ( pq.size() )
	{
		lp = pq.top(), rp = lp + 2, pq.pop();
		while ( pq.size() && pq.top() <= rp ) rp += 3, pq.pop();
		For(i, lp, rp) num[++len] = i;
	}
	For(i, 1, n) l[i] = lower_bound(num + 1, num + len + 1, l[i]) - num,
				 r[i] = lower_bound(num + 1, num + len + 1, r[i]) - num;
	len++; For(i, 1, len) buc[i].clear();
	For(i, 1, n) buc[r[i]].push_back(i);
	ST::build(1, 1, len, [&](int x) { return -x; }), fill(f + 1, f + len + 1, 0);
	For(i, 1, len)
	{
		for ( int j : buc[i] ) ST::add(1, 1, len, 1, l[j], -2);
		auto [mn, pos] = ST::qry(1, 1, len, 1, i); mn += i;
		if ( mn < -1 ) { println(-1); return; }
		if ( !~mn ) f[pos]++, f[i + 1]--;
	}
	For(i, 3, len) f[i] += f[i - 2];
	flg = true, fill(b + 1, b + len + 1, false);
	For(i, 1, len) if ( f[i] ) { flg = false; break; }
	if ( flg ) for ( int i = 1 ; i <= len ; i += 2 ) b[i] = true;
	else
	{
		ol = ql = 0, p = 1;
		For(i, 1, len) if ( f[i] ) b[i] = true, o[++ol] = i;
		for ( int i = o[ 1] - 2 ; i >=   1 ; i -= 2 ) b[i] = true;
		for ( int i = o[ol] + 2 ; i <= len ; i += 2 ) b[i] = true;
		For(i, 2, ol) 
			if ( ( o[i] - o[i - 1] ) & 1 ) q[++ql] = i;
			else for ( int j = o[i - 1] + 2 ; j < o[i] ; j += 2 ) b[j] = true;
		ST::build(1, 1, len, [&](int) { return 0; });
		For(i, 1, len)
		{
			for ( int j : buc[i] ) ST::add(1, 1, len, 1, l[j], -1);
			if ( p <= ql && i > o[q[p]] ) { println(-1); return; }
			if ( !b[i - 1] && p <= ql && i > o[q[p] - 1] + 2 && ( i - o[q[p] - 1] ) & 1 )
			{
				if ( ST::qry(1, 1, len, 1, i).first < 0 ) b[i - 1] = true;
				else { for ( int j = i ; j < o[q[p]] ; j += 2 ) b[j] = true; p++; }
			}
			if ( b[i - 1] ) ST::add(1, 1, len, 1, i, 1);
		}
	}
	iota(fa + 1, fa + len + 2, 1);
	For(i, 1, len) if ( !b[i] ) fa[i] = i + 1;
	For(i, 1, len) for ( int j : buc[i] )
	{
		if ( ( p = fat(l[j]) ) >= i ) { println(-1); return; }
		ans[j] = p, fa[p] = p + 1;
	}
	For(i, 1, n) write(num[ans[i]], i == n ? '\n' : ' ');
}
int main() { int t; read(t); For(tt, 1, t) work(); return 0; }
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 63260kb

input:

4
3
1 3
1 7
2 4
2
1 2
2 3
4
1 5
2 6
3 4
4 7
2
1 5
2 3

output:

1 5 3
-1
-1
4 2

result:

ok Valid schedules (4 test cases)

Test #2:

score: 0
Accepted
time: 7ms
memory: 65316kb

input:

5
1
1 2
1
2 4
2
2 3
1 2
2
3 4
1 2
3
1 5
2 4
3 4

output:

1
2
-1
3 1
-1

result:

ok Valid schedules (5 test cases)

Test #3:

score: 0
Accepted
time: 6ms
memory: 65444kb

input:

1
5
2 3
9 10
1 7
5 11
5 7

output:

-1

result:

ok Valid schedules (1 test case)

Test #4:

score: 0
Accepted
time: 32ms
memory: 64544kb

input:

100000
2
3 10
2 3
2
8 10
4 7
2
1 3
2 8
2
8 10
6 8
2
3 5
3 4
2
1 9
1 7
2
7 9
1 10
2
5 7
3 8
2
9 10
4 10
2
4 10
3 6
2
2 9
3 9
2
3 4
5 7
2
5 6
1 2
2
2 8
4 10
2
2 4
1 10
2
4 7
2 10
2
3 7
9 10
2
6 9
1 5
2
3 9
5 8
2
3 10
5 8
2
3 5
1 6
2
8 9
7 10
2
1 7
3 4
2
3 6
5 8
2
2 8
1 3
2
3 5
4 9
2
3 8
2 5
2
3 4
6 9
...

output:

4 2
9 4
1 3
8 6
-1
1 3
8 1
5 3
9 5
5 3
2 4
3 5
5 1
2 4
3 1
4 2
4 9
7 1
3 5
3 5
3 1
-1
1 3
3 5
3 1
3 5
4 2
3 7
2 7
4 6
6 1
4 2
7 2
6 4
6 8
2 8
7 2
3 1
4 2
5 3
3 5
3 5
3 1
1 8
5 7
9 7
2 4
6 8
1 5
4 6
6 3
3 5
4 9
3 5
5 3
8 6
1 6
5 3
8 2
2 5
-1
-1
4 6
5 1
3 1
2 4
4 2
2 8
2 4
4 2
8 4
3 9
3 1
5 3
7 5
6 1
...

result:

ok Valid schedules (100000 test cases)

Test #5:

score: -100
Wrong Answer
time: 40ms
memory: 64368kb

input:

50004
5
6 8
4 7
7 9
7 8
7 10
5
5 8
4 8
1 7
5 7
4 6
5
9 10
7 10
1 6
1 6
2 3
5
4 10
4 10
1 9
6 9
7 8
5
3 7
1 6
1 4
2 4
4 10
4
1 7
1 7
3 5
2 8
4
2 4
1 6
2 4
2 6
4
8 10
2 3
6 9
9 10
5
1 9
5 8
2 3
3 10
1 2
5
1 2
2 8
8 10
3 7
4 10
3
2 6
9 10
1 8
3
9 10
1 5
3 5
4
2 6
1 10
1 3
1 4
3
5 10
2 10
2 3
5
5 6
1 10...

output:

-1
-1
-1
-1
-1
1 5 3 7
-1
-1
-1
1 5 9 3 7
3 9 1
9 1 3
5 7 1 3
6 4 2
-1
-1
3 5 1
3 7 5 1 9
-1
-1
5 7 3 9
5 1 3 9 7
9 5 3 7 1
-1
-1
6 4 8 2
7 5 3
3 7 1
6 8 2
7 3 5 9 1
-1
-1
3 1 5
-1
7 3 1 5
1 3 7
1 5 3
4 6 2
-1
-1
-1
-1
-1
5 3 7 1 9
7 3 9 1 5
5 1 7 3
3 5 1
-1
-1
8 6 4
5 3 7
7 3 5 1 9
5 7 1 9 3
-1
-1
...

result:

wrong answer jury found an answer, participant did not (test case 26367)