QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#795572#9634. 序列zjy00010 1127ms168576kbC++1411.6kb2024-11-30 21:39:502024-11-30 21:39:51

Judging History

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

  • [2024-11-30 21:39:51]
  • 评测
  • 测评结果:0
  • 用时:1127ms
  • 内存:168576kb
  • [2024-11-30 21:39:50]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
#ifndef FASTIO
#define FASTIO
namespace 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;
#endif
const int N=5e5+5,M=N*4,INF=1e9+7;
int n,m;
LLL ans[N];
basic_string<int>E[N];
int a[N],lst[N],qi[N];
int lz[M];LL tg[M],ad[M];
basic_string<pair<int,int>>Q[N];
basic_string<tuple<int,int,int>>vec[N];
struct node{
	LLL h;LL s;int mn,se,cnt;
}T[M];
inline void pushup(node&z,const node&x,const node&y){
	z.h=x.h+y.h,z.mn=min(x.mn,y.mn);
	z.se=min(x.mn==z.mn?x.se:x.mn,y.mn==z.mn?y.se:y.mn);
	z.cnt=(x.mn==z.mn?x.cnt:0)+(y.mn==z.mn?y.cnt:0);
	z.s=x.s+y.s+(x.mn==z.mn?0:1ll*x.cnt*x.mn)+(y.mn==z.mn?0:1ll*y.cnt*y.mn);
}
inline void build(int p,int l,int r){
	T[p].se=INF,T[p].cnt=0;
	if(l==r)return;
	const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
	build(ls,l,mid),build(rs,mid+1,r);
}
inline void flip(int p,int l,int r,int x){
	if(l==r)return T[p].cnt^=1,T[p].mn=0,T[p].s=0,void();
	const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
	x<=mid?flip(ls,l,mid,x):flip(rs,mid+1,r,x);
	pushup(T[p],T[ls],T[rs]);
}
inline void tag(int p,LL v1,LL v2){
	T[p].h+=(LLL)v1*T[p].cnt,tg[p]+=v1;
	T[p].h+=(LLL)v2*T[p].s,ad[p]+=v2;
}
inline void upd(int p,int l,int r,int x,int y,int v);
inline void pushdown(int p,int l,int r){
	const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
	tag(ls,T[ls].mn<=T[rs].mn?tg[p]:ad[p]*T[ls].mn,ad[p]);
	tag(rs,T[rs].mn<=T[ls].mn?tg[p]:ad[p]*T[rs].mn,ad[p]);
	ad[p]=0,tg[p]=0;
	if(lz[p]){
		upd(ls,l,mid,l,mid,lz[p]);
		upd(rs,mid+1,r,mid+1,r,lz[p]);
		lz[p]=0;
	}
}
inline void upd(int p,int l,int r,int x,int y,int v){
	if(v<=T[p].mn)return;
	if(x<=l&&r<=y){
		if(v>=T[p].se){
			const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
			pushdown(p,l,r);
			upd(ls,l,mid,x,y,v);
			upd(rs,mid+1,r,x,y,v);
			pushup(T[p],T[ls],T[rs]);
			return;
		}
		lz[p]=max(lz[p],v),T[p].mn=v;
		return;
	}
	const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
	pushdown(p,l,r);
	if(x<=mid)upd(ls,l,mid,x,y,v);
	if(mid<y)upd(rs,mid+1,r,x,y,v);
	pushup(T[p],T[ls],T[rs]);
}
inline LLL qry(int p,int l,int r,int x,int y){
	if(x<=l&&r<=y)return T[p].h;
	const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
	pushdown(p,l,r);
	LLL z=0;
	if(x<=mid)z+=qry(ls,l,mid,x,y);
	if(mid<y)z+=qry(rs,mid+1,r,x,y);
	return z;
}
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	read(n,m);
	for(int i=1;i<=n;++i)read(a[i]);
	for(int i=1;i<=m;++i){
		int o,x,y;read(o,x,y);
		if(o==1){
			vec[x].push_back(make_tuple(lst[x],i-1,a[x]));
			a[x]=y,lst[x]=i;
		}
		else if(o==2){
			if(x<=y){
				E[x].push_back(i);
				E[y+1].push_back(i);
			}
		}
		else{
			qi[i]=1;
			if(x<=y){
				Q[x-1].push_back(make_pair(i,-1));
				Q[y].push_back(make_pair(i,1));
			}
		}
	}
	for(int i=1;i<=n;++i)vec[i].push_back(make_tuple(lst[i],m,a[i]));
	build(1,0,m);
	for(int i=1;i<=n;++i){
		for(auto p:E[i])flip(1,0,m,p);
		for(auto [l,r,v]:vec[i])upd(1,0,m,l,r,v);
		tag(1,T[1].mn,1);
		for(auto [id,o]:Q[i])ans[id]+=o*qry(1,0,m,1,id);
	}
	for(int i=1;i<=m;++i)if(qi[i])println(ans[i]);
	return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 63388kb

input:

1000 1000
200255705 18851142 736009342 406246331 351992319 749189355 944184790 785599293 530084396 616825582 73892135 176401717 973078957 225462579 140426746 324124972 229974996 750749128 879242920 854856469 515750108 662437499 10800517 96488944 534239216 379225718 1241451 150390174 183892560 613018...

output:

115323323048
65823230682
0
47574934265
60782985614
266105047116
1078078139491
-385101193078
659471379487
474560880974
1025738466176
-331399956651
1768278093141
1966594081053
3302404794840
1718127272632
-1085209841630
-113959743072
58717111123
-826473507287
3937610074378
1467726485644
2207196935817
-...

result:

wrong answer 4th lines differ - expected: '47168872319', found: '47574934265'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 116ms
memory: 90436kb

input:

100000 100000
4637 12023 22485 24887 33065 35780 37538 49402 71281 72891 82706 82752 91276 108256 240372831 135259 144119 527163065 139510686 183411 214260 269767144 246850 265137 200716505 279533 283217 309516 310867 466875375 322790 328304 352577 362081 368658 370430 393854 410075 413844 417924 42...

output:

0
0
-3521977526342
11127379027968
57610647880338
24420454084803
114192697736156
91756703259501
24666418467201
23733025959970
11037725185920
37649187455791
10016719573265
139330787118320
118731869158671
81967684186614
43151448903178
207589439352379
142208776804671
174651783315586
127837011809586
9355...

result:

wrong answer 2nd lines differ - expected: '30726293751614', found: '0'

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 239ms
memory: 114480kb

input:

199996 199998
5015 394604305 13416 39971157 16609 21608 24264 407389425 31670 31976 33151 38949 39093 43561 45026 52355 53865 59168 62183 64166 66110 67179 69567 78899 10409535 393971884 104797 109461 109501 114704 118658 123559 123907 130465 131312 140968 144801 146183 157067 160370 796894425 17818...

output:

-56158625178892
32255935469044
21829962212270
97283755019186
20609389067221
151505007772189
11850432340486
-894522097232
280981112592611
16362836209707
152521826990874
2442970418916
-60537061476754
133011672624964
502652502390154
82440864280974
344644191718937
186499558096163
73408405100248
24105826...

result:

wrong answer 1st lines differ - expected: '124830885330445', found: '-56158625178892'

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 1127ms
memory: 168576kb

input:

499996 499997
1 2646 3802 4717 7652 9462 10048 15736 15959 17076 21684 21628 25147 26990 26023 28835 33604 34213 36006 39643 38238 40133 45193 44699 47403 48437 51742 53992 57055 56322 61353 61812 62008 67837 66136 70512 72503 72294 75169 77534 81608 80173 85831 85776 87518 89661 93233 93800 96640 9...

output:

0
0
0
0
0
45221966291493
18039313761420
60123008623200
797041398707
80680885651411
0
37681746483647
71194264503086
23670062932298
32116110569411
11373629021265
44903716789361
52331311011071
16646162870752
83634907347085
50555144475855
-57750621726778
37679789480588
-33928129454001
1924388970526
7753...

result:

wrong answer 6th lines differ - expected: '105147493356021', found: '45221966291493'

Subtask #5:

score: 0
Wrong Answer

Test #19:

score: 0
Wrong Answer
time: 966ms
memory: 159472kb

input:

499999 499997
1 913 5858 7110 8076 9893 13142 12135 14769 16455 20711 22647 22330 25867 26677 28695 32280 33608 34824 39255 40515 43887 42090 46155 49082 48316 50861 55535 54485 56506 59203 61928 62076 66600 68030 69805 72680 74796 75455 79690 78235 83297 82398 85367 87069 89711 93646 92554 95923 97...

output:

48138580968621
13925555969418
141662639218402
570934969460025
339197449564061
299895982564071
-113670712078855
642953090865547
52517820498020
253988640095023
1782822036950333
1631705114125465
248522581896874
648034403210315
-1378894671008010
1555748049409301
1232563843401939
480359673477641
30342125...

result:

wrong answer 1st lines differ - expected: '103621325428465', found: '48138580968621'

Subtask #6:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 994ms
memory: 166932kb

input:

500000 499997
811 680 2664 6777 6210 8794 10852 13568 17252 18119 19538 22423 23434 24510 27591 29645 31329 33806 37129 37447 40339 41361 45606 47813 47448 50532 50029 53543 54938 56738 59038 63199 62439 67323 68737 71432 71039 75469 76122 79648 80334 81276 84567 85506 89609 91503 91445 94036 97338 ...

output:

0
0
-138402465228551
164049933648794
317934868731918
189224859108312
-189283619938220
24761798495439
38032078569662
41819803818350
39902222965786
476438972390298
8517006043528
13545269013045
385137771384066
11013700205102
242102659993566
-531300121832531
0
458815978977202
172305739079945
-5889567303...

result:

wrong answer 3rd lines differ - expected: '46530827437710', found: '-138402465228551'