QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#895937#7462. Brodal queueyaoyanfeng48 2141ms185140kbC++986.7kb2025-02-12 19:34:342025-02-12 19:34:41

Judging History

This is the latest submission verdict.

  • [2025-02-12 19:34:41]
  • Judged
  • Verdict: 48
  • Time: 2141ms
  • Memory: 185140kb
  • [2025-02-12 19:34:34]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
#define u unsigned
#define IT set<node>::iterator
#define td two_dimension_block
using namespace std;
int read()
{
	int s=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s;
}
const int mxn=2e5+5,BLOCK=1000;
struct node
{
	int l;
	mutable int r,v;
	node(int L,int R=-1,int V=0):l(L),r(R),v(V){}
	friend bool operator<(node x,node y)
    {
        return x.l<y.l;
    }
};
set<node> s; 
IT split(int w)
{
	IT it=s.lower_bound(node(w));
	if (it!=s.end()&&it->l==w) return it;
	--it;
	int r=it->r;
	it->r=w-1;         
	return s.insert(node(w,r,it->v)).first;
}
int a[mxn];
int n,cnt;
int bl[mxn],br[mxn];
int be[mxn];
int pre[mxn][mxn/BLOCK+5];
int t[mxn];
int tag[mxn];
int f[mxn/BLOCK+5][mxn/BLOCK+5];
namespace two_dimension_block
{
	const int B=21;
	int be[mxn/BLOCK+5],bl[mxn/BLOCK+5],br[mxn/BLOCK+5];
	struct two_dimension_block
	{
		int n;
		struct block
		{	
			struct block0
			{
				ll sum[mxn/BLOCK+5],a[mxn/BLOCK+5];
				int cnt;
				void add(int x,int v)
				{
					sum[be[x]]+=v,a[x]+=v;
				}
				ll ask(int x)
				{
					int i;
					ll s=0;
					for(i=bl[be[x]];i<=x;i++)
						s+=a[i];
					for(i=1;i<be[x];i++)
						s+=sum[i];
					return s;
				}
			}b1,b2;
			void add(int l,int r,ll x)
			{
				b1.add(l,x),b1.add(r+1,-x);
				b2.add(l,x*(l-1)),b2.add(r+1,-x*r);
			}
			ll ask(int x)
			{
				return b1.ask(x)*x-b2.ask(x);
			}
			ll ask(int l,int r)
			{
				return ask(r)-ask(l-1);
			}
		}b[mxn/BLOCK+5],b2[mxn/BLOCK+5];
		void build(int n_)
		{
			n=n_;
			int i,j,k,cnt=0;
			for(i=1;i<=n;i+=B)
				bl[++cnt]=i,br[cnt]=min(i+B-1,n);
			for(i=1;i<=cnt;i++)
				for(j=bl[i];j<=br[i];j++)
					be[j]=i;
		}
		void add(int x,int l,int r,int v)
		{
			if(l>r) return;
			b[x].add(l,r,v);
			b2[be[x]].add(l,r,v);
		}
		void add(int x,int y,int v)
		{
			add(x,y,y,v);
		}
		ll ask(int l1,int r1,int l2,int r2)
		{
			ll s=0;	
			if(be[l1]==be[l2])
			{
				for(;l1<=l2;l1++)
					s+=b[l1].ask(r1,r2);
				return s;
			}
			s=ask(l1,r1,br[be[l1]],r2)+ask(bl[be[l2]],r1,l2,r2);
			for(int i=be[l1]+1;i<be[l2];i++)
				s+=b2[i].ask(r1,r2);
			return s;
		}
	}ds1,ds2;
};
void init()
{
	int i,j,k;
	for(i=1;i<=n;i+=BLOCK)
		bl[++cnt]=i,br[cnt]=min(i+BLOCK-1,n);
	for(i=1;i<=cnt;i++)
		for(j=bl[i];j<=br[i];j++)
			be[j]=i,pre[a[j]][i]++;
	for(i=1;i<=n;i++)
		for(j=1;j<=cnt;j++)
			pre[i][j]+=pre[i][j-1];
	for(i=1;i<=cnt;i++)
	{
		for(k=bl[i];k<=br[i];k++)
			f[i][i]+=++t[a[k]];
		for(j=i+1;j<=cnt;j++)
			for(k=bl[j];k<=br[j];k++)
				f[i][j]+=t[a[k]];
		for(k=bl[i];k<=br[i];k++)
			t[a[k]]=0;
	}
	td::ds1.build(cnt),td::ds2.build(cnt);
	for(i=1;i<=cnt;i++)
		for(j=i;j<=cnt;j++)
			td::ds1.add(i,j,f[i][j]);
}
void pushdown(int id)
{
	if(!tag[id]) return;
	for(int i=bl[id];i<=br[id];i++)
		a[i]=tag[id];
	tag[id]=0;
}
void res(int x,bool fl)
{
	if(fl)
		for(int i=1;i<=cnt;i++)
			pre[x][i]+=pre[x][i-1];
	else
		for(int i=cnt;i>=1;i--)
			pre[x][i]-=pre[x][i-1];
}
void add(int l,int r,int x)
{
	int i;
	if(be[l]==be[r])
	{
		pushdown(be[l]);
		pre[x][be[l]]=0;		
		for(i=l;i<=r;i++)
			a[i]=x;
		for(i=bl[be[l]];i<=br[be[l]];i++)
			pre[x][be[l]]+=a[i]==x;
		return;
	}
	add(l,br[be[l]],x),add(bl[be[r]],r,x);
	for(i=be[l]+1;i<be[r];i++)
		tag[i]=x,pre[x][i]=br[i]-bl[i]+1;
}
void del(int l,int r,int x)
{
	int i;
	if(be[l]==be[r])
	{
		pushdown(be[l]);
		pre[x][be[l]]=0;		
		for(i=l;i<=r;i++)
			a[i]=0;
		for(i=bl[be[l]];i<=br[be[l]];i++)
			pre[x][be[l]]+=a[i]==x;
		return;
	}
	del(l,br[be[l]],x),del(bl[be[r]],r,x);
	for(i=be[l]+1;i<be[r];i++)
		pre[x][i]=0;
}
int F(int x)
{
	return (x+1)*x/2;
}
void addf(int l,int r,int x,int v)
{
	int i,j,p,len=r-l+1;
	if(be[l]==be[r])
	{
		for(i=1;i<be[l];i++)
			td::ds1.add(i,be[l],v*(pre[x][i]-pre[x][i-1])*len);
		td::ds1.add(be[l],be[l],v*(F(pre[x][be[l]]-pre[x][be[l]-1])-F(pre[x][be[l]]-pre[x][be[l]-1]-len)));
		for(i=be[l]+1;i<=cnt;i++)
			td::ds1.add(be[l],i,v*(pre[x][i]-pre[x][i-1])*(r-l+1));
		return;
	}
	for(i=1;i<be[l];i++)
	{
		p=pre[x][i]-pre[x][i-1];
		td::ds1.add(i,be[l],v*p*(br[be[l]]-l+1));
		td::ds1.add(i,be[r],v*p*(r-bl[be[r]]+1));
		td::ds1.add(i,be[l]+1,be[r]-1,v*BLOCK*p);
	}
	p=pre[x][be[l]]-pre[x][be[l]-1],len=br[be[l]]-l+1;
	td::ds1.add(be[l],be[l],v*(F(p)-F(p-len)));
	td::ds1.add(be[l],be[l]+1,be[r]-1,v*BLOCK*p);
	td::ds1.add(be[l],be[r],v*(p*(pre[x][be[r]]-pre[x][be[r]-1])-(p-len)*(pre[x][be[r]]-pre[x][be[r]-1]-(r-bl[be[r]]+1))));
	for(i=be[r]+1;i<=cnt;i++)
		td::ds1.add(be[l],i,v*(pre[x][i]-pre[x][i-1])*len);
	for(i=be[l]+1;i<be[r];i++)
	{
		td::ds1.add(i,i,v*BLOCK*(BLOCK+1)/2);
		td::ds1.add(i,i+1,be[r]-1,v*BLOCK*BLOCK);
		td::ds1.add(i,be[r],v*BLOCK*(pre[x][be[r]]-pre[x][be[r]-1]));
	}
	for(j=be[r]+1;j<=cnt;j++)
		td::ds2.add(j,be[l]+1,be[r]-1,v*(pre[x][j]-pre[x][j-1])*BLOCK);
	p=pre[x][be[r]]-pre[x][be[r]-1],len=r-bl[be[r]]+1;
	td::ds1.add(be[r],be[r],v*(F(p)-F(p-len)));
	for(i=be[r]+1;i<=cnt;i++)
		td::ds1.add(be[r],i,v*(pre[x][i]-pre[x][i-1])*len);
}
void as(int l,int r,int v)
{
	if(l<1||r>n||l>r||v<1||n>n) return;
	IT itr=split(r+1),itl=split(l),i;
	for(i=itl;i!=itr;i++)
		addf(i->l,i->r,i->v,-1),res(i->v,0),del(i->l,i->r,i->v),res(i->v,1);
	res(v,0),add(l,r,v),res(v,1);
	addf(l,r,v,1);
	s.erase(itl,itr);
	s.insert(node(l,r,v));
}
u ask(int l,int r)
{
	if(l<1||r>n||l>r) return 0;
	int i,len=r-l+1;
	ll s=0;
	if(be[l]==be[r])
	{
		if(tag[be[l]])
			return printf("%lld\n",(r-l+1ll)*(r-l)/2),(r-l+1ll)*(r-l)/2;
		for(i=l;i<=r;i++)
			s+=++t[a[i]];
		for(i=l;i<=r;i++) t[a[i]]=0;
		return printf("%lld\n",s-len),s-len;
	}
	pushdown(be[l]),pushdown(be[r]);
	if(be[l]+1<be[r]) s=td::ds1.ask(be[l]+1,be[l]+1,be[r]-1,be[r]-1)+td::ds2.ask(be[l]+1,be[l]+1,be[r]-1,be[r]-1);
	for(i=l;i<=br[be[l]];i++)
		s+=pre[a[i]][be[r]-1]-pre[a[i]][be[l]]+(++t[a[i]]);
	for(i=bl[be[r]];i<=r;i++)
		s+=pre[a[i]][be[r]-1]-pre[a[i]][be[l]]+(++t[a[i]]);
	for(i=l;i<=br[be[l]];i++) t[a[i]]=0;
	for(i=bl[be[r]];i<=r;i++) t[a[i]]=0;
	return printf("%lld\n",s-len),s-len;
}
void print()
{
	for(int i=1;i<=cnt;i++)
		pushdown(i);
	for(int i=1;i<=cnt;i++,cout<<'|')
		for(int j=bl[i];j<=br[i];j++)
		cout<<a[j]<<' ';
	cout<<':'<<endl;
	for(int i=1;i<=cnt;i++,cout<<endl)
		for(int j=1;j<=cnt;j++)
			cout<<f[i][j]<<' ';
}
int main()
{
//	freopen("in","r",stdin);
//	freopen("out","w",stdout);
	n=read();
	int m=read(),i,opt,l,r;
	u last=0;
	for(i=1;i<=n;i++)
		s.insert(node(i,i,a[i]=read()));
	init();
	while(m--)
	{
		opt=read(),l=read()^last,r=read()^last;	
		if(opt==1) as(l,r,read()^last);
		else last=ask(l,r);
	}
}

詳細信息

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 0ms
memory: 11920kb

input:

10 12
6 9 9 4 7 8 10 4 9 2
2 1 4
1 0 5 0
2 3 6
2 10 9
1 7 9 2
2 7 9
1 2 7 1
1 2 11 4
2 6 10
1 3 12 0
1 14 14 15
2 7 12

output:

1
3
0
3
6
16

result:

ok 6 numbers

Subtask #2:

score: 9
Accepted

Test #2:

score: 9
Accepted
time: 997ms
memory: 185140kb

input:

200000 200000
1801 1645 561 1609 920 737 249 121 609 966 220 209 641 761 1475 284 595 220 1853 905 1705 399 1737 264 551 681 119 81 1529 1884 1905 641 257 1241 241 401 675 442 505 1565 1391 1395 1803 1589 55 1521 945 229 167 1030 996 73 1473 387 400 1261 1559 405 1573 1823 1029 937 17 1810 1885 401 ...

output:

28358
517270
14881
2254491
8001066
1545378
642772
110901
407089
452894
666513
54715
1625913
1441
6923245
9696
49136
816131
2509617
1312876
343815
456703
1356423
1836337
1746327
660004
1089819
13914095
2148442
10048565
5171534
4750216
4919749
101478
577992
1103366
2608074
8109
519702
50997
5176718
95...

result:

ok 200000 numbers

Test #3:

score: 9
Accepted
time: 750ms
memory: 182748kb

input:

200000 200000
17 183 173 114 41 1 53 88 168 151 98 126 41 63 151 141 26 70 171 97 189 20 41 90 33 27 181 193 11 67 194 9 193 21 121 73 49 183 23 53 179 101 173 101 181 151 113 41 41 200 87 61 21 160 21 197 137 1 178 165 25 17 99 101 123 41 141 179 18 135 9 63 93 1 17 121 181 165 23 84 151 72 185 195...

output:

57453674
8912267
106941240
43372080
3514
4140700
70940924
866065
45821048
93782304
2960142
6633447
4220263
2087922
23603247
16758529
39062682
28259929
13332277
4977435
60030213
8090899
242318
133034690
40197440
8097004
41318154
4955270
45526625
7549867
14419640
22190442
920
1509331
113034320
3984547...

result:

ok 200000 numbers

Test #4:

score: 9
Accepted
time: 803ms
memory: 182596kb

input:

200000 200000
1 1 1 1 1 1 1 1 2 1 1 2 2 1 1 1 1 1 2 2 1 1 2 1 1 2 1 1 2 1 1 1 2 2 2 1 1 1 1 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 2 2 2 2 1 1 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 ...

output:

20458927
2278131900
5335501156
1812018679
794532792
213524614
807699550
679149900
2715059560
5276018812
1839228536
246261631
3409678917
492124212
36827175
6883274572
11190063
1028136358
2601277905
8103196
3723752846
84746491
3612860367
8310108440
2108227681
33432402
618846546
571630
141952752
517795...

result:

ok 200000 numbers

Subtask #3:

score: 19
Accepted

Dependency #1:

100%
Accepted

Test #5:

score: 19
Accepted
time: 0ms
memory: 12148kb

input:

500 500
281 301 126 111 121 485 237 185 243 443 279 146 116 365 413 403 227 461 79 215 136 58 442 385 416 31 421 260 77 89 231 196 401 409 406 385 421 331 193 193 251 79 76 301 364 222 286 129 437 91 181 77 389 11 303 217 318 391 69 171 477 1 26 225 87 385 253 86 41 217 59 399 186 249 391 61 373 416...

output:

13
166
36
7
75
2
37
7261
21989
22791
9394
2981
10
10324
45
3321
17296
9018
1128
1495
210
6226
10591
12387
5202
2953
6985
465
20366
10223
9493
14196
4934
45
15576
5251
8881
48948
22578
33299
153
20155
820
3381
31878
1282
11752
6643
1442
23822
3
43876
3486
15576
2121
4591
1081
4095
16662
210
14130
881...

result:

ok 263 numbers

Test #6:

score: 19
Accepted
time: 1ms
memory: 12284kb

input:

500 500
21 39 5 25 25 35 9 11 29 31 9 43 36 41 14 26 6 11 37 43 37 31 1 41 35 1 1 22 7 5 41 35 15 30 45 1 9 13 47 1 33 31 26 16 17 7 19 6 6 11 31 19 17 35 1 15 25 3 11 11 9 29 3 31 17 17 50 19 13 36 33 15 46 44 35 41 39 15 1 9 32 36 6 33 29 13 49 15 13 11 25 13 21 45 27 26 15 40 47 33 21 17 2 7 6 45...

output:

13954
12
13235
14316
6976
3235
22147
9845
16963
15030
2815
2199
3598
1080
564
105
44
15
35995
38233
1424
10962
13730
1081
18
9673
20089
2908
2926
5253
3602
472
21115
12561
48342
26565
3672
41622
3282
6786
24753
20110
595
18683
91
6335
0
35998
561
66
11959
8778
23279
3457
15
4662
37026
69045
210
1414...

result:

ok 238 numbers

Subtask #4:

score: 19
Accepted

Dependency #2:

100%
Accepted

Test #7:

score: 19
Accepted
time: 2027ms
memory: 182904kb

input:

200000 200000
42117 11359 41220 12879 46629 34683 41056 7257 25769 48971 43167 9001 4589 3689 16459 23491 30843 15858 43281 24001 25831 43921 43680 19593 37551 43235 488 11642 36361 28687 23661 38456 16817 39826 30687 28321 6961 35601 20653 21989 32641 38223 15626 24193 15209 36626 36576 17166 14001...

output:

418951
29901
177
141979
53172
29610
756
1876
175800
9203
19666
46632
10724
195643
64577
57117
113508
68182
52178
55297
172867
220232
71578
39447
108116
395819
60262
169911
24597
38336
214485
27264
201704
51291
249199
64
2231
148307
8203
136171
52703
34537
37939
6771
9211
147445
96648
189649
71870
85...

result:

ok 100514 numbers

Test #8:

score: 19
Accepted
time: 1787ms
memory: 183224kb

input:

200000 200000
2094 13606 17209 1873 18859 6265 6245 11773 14287 19671 17616 13525 12246 5583 11447 13181 12665 1041 4997 5587 12324 12517 9481 1251 13631 722 1523 1929 11155 9707 16673 3345 4854 16921 10217 18207 4629 17942 10673 2943 703 7933 7875 15021 5927 15601 9697 16136 17721 6176 6908 11811 1...

output:

6786
976233
683302
837868
2556
64432
109979
47244
282235
462112
22501
104932
423093
85552
25773
195691
118604
5845
5448
107987
203526
1036941
432
307987
120164
36365
1097726
94
432831
106359
6608
412747
8328
62179
808652
7562
715421
557964
328521
226643
358187
244217
1360482
14610
15605
15755
77992
...

result:

ok 100482 numbers

Test #9:

score: 19
Accepted
time: 2141ms
memory: 184908kb

input:

200000 200000
961 24296 97295 72651 57317 19319 91619 73701 48517 37111 94997 39305 53513 48409 84619 65223 89009 23316 29209 32233 30796 39149 91689 79043 87481 32425 79805 60726 10545 11060 58706 67287 70435 77825 95601 14986 28745 19804 45141 11457 32853 12910 13237 37950 28036 24657 67606 60086 ...

output:

137
7231
95882
30804
322
6150
72179
7299
147301
10974
411
6499
36201
16150
189291
62115
22632
180243
32578
80639
32559
32558
7551
92599
133447
12680
8316
58120
91884
55641
572
59976
922
974
155290
39321
1204
762
220492
69487
131948
161623
10592
2058
27071
143268
265584
122947
40499
3623
2841
24689
6...

result:

ok 100481 numbers

Test #10:

score: 19
Accepted
time: 1676ms
memory: 181032kb

input:

200000 200000
939 351 2485 2308 3586 3824 2761 4927 4521 585 2513 3295 3505 553 4909 531 4661 3169 871 3648 4710 4265 4913 1016 3375 2676 4159 801 2286 358 636 1371 4401 305 1191 1651 3071 751 159 2089 1539 2581 1921 1891 325 1734 1449 2973 360 401 4811 1433 3181 3224 3441 3537 1269 589 3356 407 581...

output:

42764
3319484
5357223
1586462
164844
1092132
92088
79783
1039300
4297640
3234739
466774
303914
660281
108250
19293
1133615
41995
23226
486773
63659
443375
241081
197402
20404
4529155
2267499
143206
2217491
511989
4263062
1749723
218909
20729
226867
93031
318798
110184
54608
172443
1104003
990836
211...

result:

ok 100469 numbers

Test #11:

score: 19
Accepted
time: 1443ms
memory: 183516kb

input:

200000 200000
43 71 75 49 41 65 61 56 19 31 23 18 45 69 72 85 73 79 63 24 51 67 53 61 52 83 29 40 26 11 81 17 79 49 49 41 84 61 21 41 6 83 39 97 66 99 70 4 17 75 5 73 73 5 33 97 21 91 37 1 73 21 88 53 51 45 65 13 90 43 46 15 34 41 68 83 21 59 85 1 5 91 17 1 19 33 5 36 25 11 9 36 51 95 15 25 81 18 99...

output:

49108672
77917023
1069397
1271813
74163387
2246899
107098403
59105334
79770716
2729313
92819674
14031181
262774398
4024365
23512159
42274108
14149209
47182573
61820938
28853075
109290
120477336
5487313
150551739
49032231
577797
4719178
1612600
486016
49307123
138955266
13505802
18974813
523301
34451...

result:

ok 100459 numbers

Subtask #5:

score: 0
Time Limit Exceeded

Test #12:

score: 0
Time Limit Exceeded

input:

200000 200000
96162 15481 51305 66323 58345 67841 63351 179462 4914 118157 110677 76845 126971 69269 112773 199665 196553 135326 72861 194617 101133 147301 186526 55880 25433 71005 84700 54329 127457 80123 92345 198413 118472 128393 52712 178299 77837 30176 186913 88131 184501 51913 138202 142540 17...

output:

61487
18213
538754
9208486
2827151001
435128213
197337174
10841496
63467011
69331200
1337604281
1788330451
1622013202
1268525593
2097519070
255572136
8864376162
132934665
7413238977
3799037054
767017946
2841968268
1998310281
53898153
134537406
656686920
1920829680
29467951
114547402
856375126
663208...

result:


Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

0%