QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#154113#6533. Traveling in Cellsucup-team896#AC ✓754ms85608kbC++239.6kb2023-08-31 13:46:012023-08-31 13:46:01

Judging History

你现在查看的是最新测评结果

  • [2023-08-31 13:46:01]
  • 评测
  • 测评结果:AC
  • 用时:754ms
  • 内存:85608kb
  • [2023-08-31 13:46:01]
  • 提交

answer

/*
 * @Author:             cmk666
 * @Created time:       2023-08-31 13:17:18
 * @Last Modified time: 2023-08-31 13:45:51
 */
#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 BIT
{
	using T = ll; int n; T c[100009];
	inline int lowbit(int x) { return x & -x; }
	inline void init(int x) { n = x, fill(c + 1, c + n + 1, 0); }
	inline void add(int x, T y) { for ( ; x <= n ; x += lowbit(x) ) c[x] += y; }
	inline T query(int x) { T y = 0; for ( ; x ; x ^= lowbit(x) ) y += c[x]; return y; }
	inline T query(int x, int y) { return query(y) - query(x - 1); }
}
namespace ST
{
	struct node
	{
		int v, lc, rc;
	}	t[10000009]; int cnt;
	inline int &lc(int x) { return t[x].lc; }
	inline int &rc(int x) { return t[x].rc; }
	inline int md(int x, int y) { return ( x + y ) >> 1; }
	inline void pu(int p) { t[p].v = t[lc(p)].v + t[rc(p)].v; }
	inline void add(int &p, int l, int r, int pos, int v)
	{
		if ( !p ) p = ++cnt;
		if ( l == r ) { t[p].v += v; return; }
		pos <= md(l, r) ? add(lc(p), l, md(l, r), pos, v)
						: add(rc(p), md(l, r) + 1, r, pos, v), pu(p);
	}
	inline int pre(const auto &p, int l, int r, int pos)
	{
		if ( l > pos ) return -1;
		int sum = 0;
		for ( int i : p ) if ( i ) sum += t[i].v;
		if ( sum == r - l + 1 ) return -1;
		if ( l == r ) return l;
		vector < int > c;
		for ( int i : p ) c.push_back(rc(i));
		int ret = pre(c, md(l, r) + 1, r, pos);
		if ( ~ret ) return ret;
		c.clear();
		for ( int i : p ) c.push_back(lc(i));
		return pre(c, l, md(l, r), pos);
	}
	inline int nxt(const auto &p, int l, int r, int pos)
	{
		if ( r < pos ) return -1;
		int sum = 0;
		for ( int i : p ) if ( i ) sum += t[i].v;
		if ( sum == r - l + 1 ) return -1;
		if ( l == r ) return l;
		vector < int > c;
		for ( int i : p ) c.push_back(lc(i));
		int ret = nxt(c, l, md(l, r), pos);
		if ( ~ret ) return ret;
		c.clear();
		for ( int i : p ) c.push_back(rc(i));
		return nxt(c, md(l, r) + 1, r, pos);
	}
}
int n, q, c[100009], v[100009], op, x, y, z, rt[100009], l, r; vector < int > nw;
inline void work()
{
	read(n, q), BIT::init(n), fill(rt + 1, rt + n + 1, 0);
	For(i, 1, n) read(c[i]), ST::add(rt[c[i]], 1, n, i, 1);
	For(i, 1, n) read(v[i]), BIT::add(i, v[i]);
	For(_, 1, q)
	{
		read(op, x, y);
		if ( op == 1 ) ST::add(rt[c[x]], 1, n, x, -1), ST::add(rt[c[x] = y], 1, n, x, 1);
		if ( op == 2 ) BIT::add(x, -v[x]), BIT::add(x, v[x] = y);
		if ( op == 3 )
		{
			nw.clear();
			For(i, 1, y) read(z), nw.push_back(rt[z]);
			l = ST::pre(nw, 1, n, x), r = ST::nxt(nw, 1, n, x);
			l = ~l ? l + 1 : 1, r = ~r ? r - 1 : n;
			println(BIT::query(l, r));
		}
	}
}
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: 1ms
memory: 7696kb

input:

2
5 10
1 2 3 1 2
1 10 100 1000 10000
3 3 1 3
3 3 2 2 3
2 5 20000
2 3 200
3 3 2 1 3
3 3 3 1 2 3
1 3 4
2 1 100000
1 2 2
3 1 2 1 2
4 1
1 2 3 4
1000000 1000000 1000000 1000000
3 4 4 1 2 3 4

output:

100
110
1200
21211
100010
4000000

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 159ms
memory: 23172kb

input:

20000
15 15
1 1 3 3 2 3 3 3 3 3 2 3 2 3 3
634593973 158136379 707704004 998369647 831633445 263092797 937841412 451774682 552617416 483763379 50360475 794662797 74247465 537217773 901809831
3 6 4 1 3 5 10
3 5 7 1 2 3 4 5 9 10
3 4 3 3 8 9
2 13 608033129
3 15 2 3 5
1 9 3
3 8 4 1 3 7 10
2 6 727472865
3...

output:

2689089686
8377825475
1706073651
1439027604
2689089686
792730352
8904867081
8904867081
8270273108
831633445
692051585
2782432626
697783016
883944422
184057757
287523250
184057757
696388752
184057757
1675459344
2667693025
2614711258
4006992373
1767091974
5348541057
5348541057
390631780
2290216252
942...

result:

ok 200062 numbers

Test #3:

score: 0
Accepted
time: 304ms
memory: 24764kb

input:

2000
150 150
8 3 8 8 8 6 8 4 2 7 6 8 8 5 8 7 7 8 5 6 8 8 6 8 8 8 8 7 8 6 6 8 8 8 6 2 3 4 8 8 7 8 5 8 2 6 8 7 8 8 6 8 6 8 3 8 8 8 8 4 7 8 7 3 7 6 7 5 5 8 6 8 8 6 3 8 6 7 6 8 8 7 4 8 6 7 8 7 7 7 7 8 8 8 8 2 5 2 8 8 6 7 6 3 8 8 7 8 8 8 6 6 8 6 6 7 5 8 8 8 7 8 7 7 6 8 8 8 8 8 8 6 5 7 5 5 8 7 8 7 7 7 6 5...

output:

4449391171
3290849667
852793841
5178673994
995994209
11431868919
4327723427
5071541023
3032743466
962345334
2997656427
4534278452
3851900075
3611231417
5071541023
1477584218
1299005818
1299005818
2145605244
854143763
886347565
2081234124
2333808475
2455955801
4179722063
2328504333
1473735464
4107685...

result:

ok 199987 numbers

Test #4:

score: 0
Accepted
time: 535ms
memory: 27560kb

input:

10
30000 30000
3 4 2 4 4 4 4 3 4 3 4 3 4 3 4 4 2 4 4 4 4 4 3 3 3 4 3 4 3 4 3 3 4 2 4 3 3 3 3 4 3 4 4 4 4 2 3 3 4 2 3 4 4 4 4 1 4 4 4 4 4 4 4 4 3 3 3 4 4 4 4 4 2 3 4 4 4 4 3 4 4 3 3 3 4 4 3 4 4 2 3 4 4 4 4 3 2 4 3 4 3 2 4 4 3 4 2 2 4 4 4 4 2 4 3 2 4 4 3 4 4 4 2 4 4 3 2 3 2 3 3 3 4 2 4 3 4 1 4 3 4 4 4...

output:

6959437173
934970676
72461245502
8365928740
8384151048
984567228
12482909122
1904927816
15134139942
3759040688
92670874909
332468911
5936663371
3562978848
1300592004
10314009201
5581540905
131246926443
15087184135864
4077066271
1124704817
1520626740
4388174158
744377942
2770411457
6231852240
1508724...

result:

ok 200135 numbers

Test #5:

score: 0
Accepted
time: 448ms
memory: 26308kb

input:

3
100000 100000
6 6 2 6 5 3 6 5 4 6 4 6 6 6 6 5 2 5 2 6 6 6 1 6 5 6 4 5 6 6 5 4 5 4 3 4 5 5 6 6 5 6 6 5 2 5 6 5 4 2 5 6 6 6 5 2 5 6 6 4 5 6 3 3 6 5 6 5 5 5 5 4 4 4 4 3 6 5 4 5 6 5 6 6 6 6 3 6 5 6 5 4 3 5 6 4 5 3 6 5 3 5 6 4 6 5 4 5 5 5 2 5 4 6 6 3 5 5 5 5 5 4 5 5 6 5 5 6 6 6 5 5 4 6 5 4 4 2 6 6 6 5 ...

output:

753014823
938372065
5655899645
168297301
14372254310
1066586326
3520855082
2591792266
2321844837
64378192092
250581310
1845085639
1402247975
198007248
2157074263
2743531397
3433471688
10332600792
1085086491
4845484125
50019185900042
4036199358
154762798
50019185900042
1221387905
11240790307
10537215...

result:

ok 199749 numbers

Test #6:

score: 0
Accepted
time: 754ms
memory: 54788kb

input:

3
100000 100000
173 276 418 362 183 321 401 316 193 426 212 126 206 409 382 443 405 412 259 233 356 355 340 41 354 447 421 464 436 436 329 239 427 415 452 424 174 294 220 413 293 456 140 304 438 462 418 345 160 296 443 234 455 452 396 347 438 413 235 416 363 186 340 285 340 457 392 359 451 310 431 1...

output:

832547880
1825993219
676042867
310750190
650714631
657481975
1279322
838513014
453432678
940357183
846050641
631145680
278723792
689448062
154699248
45678908
56518237
839298643
611124630
499104412
324172054
742064269
626600147
728123335
602272914
45485542
868574266
876207167
342300121
917221167
7055...

result:

ok 200119 numbers

Test #7:

score: 0
Accepted
time: 737ms
memory: 85608kb

input:

3
100000 100000
66046 49249 42478 61684 59308 38366 66208 38769 50465 63701 50193 47811 50312 56793 58616 63383 58390 17546 23446 57532 59030 63009 62771 46338 52747 54677 68893 58360 56617 42330 65075 51193 65417 67035 54247 54323 39404 61892 42821 30094 67958 46206 53273 28507 65864 42364 64063 46...

output:

787181803
340358691
794440759
970166774
501256821
822531703
505349238
299646179
317091968
718901636
589846615
490283989
1183290
98835675
715091970
941598117
81757251
249078591
559980949
587721512
408541247
542135558
217103011
916103998
422219165
786665928
215595722
309683697
275650079
660176857
9707...

result:

ok 199750 numbers

Test #8:

score: 0
Accepted
time: 441ms
memory: 51236kb

input:

3
100000 100000
2 2 3 1 1 3 1 3 1 1 1 1 1 3 3 2 3 1 1 3 3 3 2 1 2 3 2 3 1 1 2 2 2 3 1 1 3 3 3 3 1 3 1 1 3 2 3 1 1 2 3 3 2 1 3 1 1 1 2 3 3 2 3 3 1 1 2 2 2 1 1 3 1 1 2 2 1 3 3 3 2 1 1 2 1 2 3 3 3 2 2 3 3 2 3 2 1 3 3 3 2 2 3 1 3 2 3 2 3 1 2 2 1 2 1 3 3 3 2 2 3 1 3 2 1 1 1 2 1 2 2 1 3 1 2 1 1 3 3 2 3 3 ...

output:

50035938417434
50036115992265
50036315519498
3975347985
50036470174447
50036191297549
7222739016
50036248757817
1886106914
50037215621946
50037215621946
50037215621946
50037789462602
50037789462602
50038171558883
50038171558883
50038171558883
50037356071541
50037356071541
840665598
50037454922987
19...

result:

ok 144306 numbers

Test #9:

score: 0
Accepted
time: 625ms
memory: 48292kb

input:

3
100000 100000
60522 14575 36426 79445 48772 90081 33447 90629 3497 47202 7775 94325 63982 4784 68417 2156 31932 35902 95728 78537 23857 30739 86918 29211 39679 38506 63340 86568 61868 60016 87940 96263 24593 1449 36991 90310 23355 77068 11431 8580 91757 49218 74934 94328 63676 29355 96221 99080 95...

output:

49028798194951
49028798194951
49028798194951
445374817
49028798194951
49028798194951
49028798194951
49028798194951
49029113499144
49029113499144
49029113499144
568084096
49029252709603
49029252709603
49029252709603
49029252709603
49029252709603
49029252709603
49029252709603
142834402
644706458
49029...

result:

ok 151536 numbers

Test #10:

score: 0
Accepted
time: 49ms
memory: 28744kb

input:

3
100000 100000
2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 ...

output:

50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
50042766706436
...

result:

ok 300000 numbers