QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#498881#5057. Prof. Pang's sequenceMisaka16172WA 572ms114100kbC++144.6kb2024-07-30 20:58:522024-07-30 20:58:52

Judging History

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

  • [2024-07-30 20:58:52]
  • 评测
  • 测评结果:WA
  • 用时:572ms
  • 内存:114100kb
  • [2024-07-30 20:58:52]
  • 提交

answer

#include <bits/stdc++.h>
#define pii pair<int,int>
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define mp_ make_pair
#define pb_ push_back
#define pob_ pop_back
#define fst first
#define snd second
#define debug cout<<"********\n";
#define reset(x,y) memset(x,y,sizeof(x))
#define fi(x) freopen(x,"r",stdin)
#define fo(x) freopen(x,"w",stdout)
#define iosf ios::sync_with_stdio(0);cin.tie(0);
#define prec(x) cout<<setprecision(x);
#define prec0(x) cout<<fixed<<setprecision(x);
#define Misaka16172 sb
#define kamisako femboy

using ll = long long;
using ld = long double;
using db = double;
using ull = unsigned long long;
using uint = unsigned int;

constexpr int inf = 0x3f3f3f3f;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ull mod1 = 1e9+7,mod9 = 998244353;

using namespace std;

template <class T>
inline void read(T &x){
    x = 0;T w = 1;
    char c = 0;
    while(!isdigit(c)){
        if(c=='-')  w = -1;
        c = getchar();
    }
    while(isdigit(c)){
        x = ((x<<3)+(x<<1))+c-'0';
        c = getchar();
    }
    x = x*w;
}
template<class T,typename ...Args>
inline void read(T &x,Args &...rest){read(x);read(rest...);}

template<class T>
inline void write(T x){
    if(!x)  return putchar('0'),void();
    else if(x<0) putchar('-'),x*=-1;
    int st[40],t = 0;
    while(x){st[++t] = x%10,x/=10;}
    while(t){putchar(st[t--]+'0');}
}

template <class T>
inline string bin(T x,int d = 0){return (((d>1)||(x>>1))?bin(x>>1,d-1):"")+to_string(x&1);}

int Test = 1,Case = 1;

constexpr int N = 5e5+5;

template<int X,int Y>
struct mat{
	ll a[X][Y];
	mat(){}
	mat(int val){
		for(int y=0;y<Y;y++){
			for(int x=0;x<X;x++)	a[x][y] = val;
		}
	}
	mat(vector<vector<ll>> _a){
		for(int y=0;y<Y;y++){
			for(int x=0;x<X;x++)	a[x][y] = _a[x][y];
		}
	}
	template<int _X,int _Y>
	inline bool operator ==(const mat<_X,_Y> &m)const{
		if(X!=_X || Y!=_Y)	return 0;
		for(int y=0;y<Y;y++){
			for(int x=0;x<X;x++)	if(a[x][y]!=m.a[x][y])	return 0;
		}
		return 1;
	}
	template<int _X,int _Y>
	inline bool operator !=(const mat<_X,_Y> &m)const{return !(*this==m);}
	template<int _X,int _Y>
	inline mat<_X,Y> operator *(const mat<_X,_Y> &m)const{
		mat<_X,Y> res;
		for(int y=0;y<Y;y++){
			for(int x=0;x<_X;x++){
				res.a[x][y] = 0;
				for(int i=0;i<X;i++)	res.a[x][y]+=m.a[x][i]*a[i][y];
			}
		}
		return res;
	}
	inline mat<X,Y> operator +(const mat<X,Y> &m)const{
		mat<X,Y> res;
		for(int y=0;y<Y;y++){
			for(int x=0;x<X;x++)	res.a[x][y] = a[x][y]+m.a[x][y];
		}
		return res;
	}
	template<int x,int y>
	inline ll get(){return a[x-1][y-1];}
	template<int x,int y>
	inline void upd(ll v){a[x-1][y-1] = v;}
};

const mat<3,3> de = mat<3,3>({{1,0,0},{0,1,0},{0,0,1}});

int n,a[N];

struct node{
	mat<1,3> v;
	mat<3,3> t;
};

struct SGT{
	node tr[N<<2];
	inline void up(int p){tr[p].v = tr[p<<1].v+tr[p<<1|1].v;}
	inline void down(int p){
		if(tr[p].t!=de){
			tr[p<<1].t = tr[p].t*tr[p<<1].t,tr[p<<1|1].t = tr[p].t*tr[p<<1|1].t;
			tr[p<<1].v = tr[p].t*tr[p<<1].v,tr[p<<1|1].v = tr[p].t*tr[p<<1|1].v;
			tr[p].t = de;
		}
	}
	void build(int l,int r,int p){
		tr[p].t = de;
		if(l==r)	tr[p].v = mat<1,3>({{0,0,1}});
		else{
			int mid = (l+r)>>1;
			build(l,mid,p<<1),build(mid+1,r,p<<1|1);
			up(p);
		}
	}
	void mul(int l,int r,int nl,int nr,int p,mat<3,3> v){
		if(nl^nr)	down(p);
		if(nl>=l && nr<=r){
			tr[p].v = v*tr[p].v;
			if(nl^nr)	tr[p].t = v*tr[p].t;
		}
		else{
			int mid = (nl+nr)>>1;
			if(mid>=l)	mul(l,r,nl,mid,p<<1,v);
			if(mid+1<=r)	mul(l,r,mid+1,nr,p<<1|1,v);
			up(p);
		}
	}
	ll query(int l,int r,int nl,int nr,int p,int t){
		if(nl^nr)	down(p);
		if(nl>=l && nr<=r)	return tr[p].v.get<1,1>()*t+tr[p].v.get<1,2>();
		else{
			int mid = (nl+nr)>>1;
			ll res = 0;
			if(mid>=l)	res+=query(l,r,nl,mid,p<<1,t);
			if(mid+1<=r)	res+=query(l,r,mid+1,nr,p<<1|1,t);
			return res;	
		}
	}
}sgt;

struct Query{
	int l,r,id;
	inline bool operator <(const Query &q)const{return r<q.r;}
}Q[N];

int q,lst[N],ans[N];

void solve(){
    read(n);
    for(int i=1;i<=n;i++)	read(a[i]);
    read(q);
	for(int i=1;i<=q;i++)	read(Q[i].l,Q[i].r),Q[i].id = i;
	sort(Q+1,Q+1+q);
	int p = 1;
	sgt.build(1,n,1);
	for(int r=1;r<=n;r++){
		mat<3,3> d = mat<3,3>({{-1,2*(r-1),0},{0,1,0},{1,-(r-1),1}});
		sgt.mul(lst[a[r]]+1,r,1,n,1,d);
		lst[a[r]] = r;
		while(p<=q && Q[p].r==r){
			ans[Q[p].id] = sgt.query(Q[p].l,r,1,n,1,r);
			p++;
		}
	}
	for(int i=1;i<=q;i++)	cout<<ans[i]<<"\n";
}

int main(){
//  read(Test);
    for(;Case<=Test;++Case) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9928kb

input:

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

output:

10
3
4
6
1

result:

ok 5 number(s): "10 3 4 6 1"

Test #2:

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

input:

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

output:

2
1
4
6
4

result:

ok 5 number(s): "2 1 4 6 4"

Test #3:

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

input:

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

output:

4
2
4
4
16
16
12
6
9
6

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 7696kb

input:

100
2 8 5 1 10 5 9 9 3 5 6 6 2 8 2 2 6 3 8 7 2 5 3 4 3 3 2 7 9 6 8 7 2 9 10 3 8 10 6 5 4 2 3 4 4 5 2 2 4 9 8 5 3 8 8 10 4 2 10 9 7 6 1 3 9 7 1 3 5 9 7 6 1 10 1 1 7 2 4 9 10 4 5 5 7 1 7 7 2 9 5 10 7 4 8 9 9 3 10 2
100
16 34
40 59
5 31
7 78
74 87
22 46
25 73
30 71
74 78
13 98
87 91
37 62
56 68
56 75
3...

output:

88
112
186
1260
61
209
547
382
9
1453
9
186
48
117
123
1
104
317
1540
264
317
294
453
867
945
208
159
891
1701
21
872
63
334
683
768
659
703
1116
679
77
447
639
130
1619
415
868
334
63
22
2
21
81
754
474
1799
85
424
1626
37
644
856
40
718
558
80
90
30
829
607
669
363
391
394
1151
724
251
87
115
200
...

result:

ok 100 numbers

Test #5:

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

input:

100
42 68 35 1 70 25 79 59 63 65 6 46 82 28 62 92 96 43 28 37 92 5 3 54 93 83 22 17 19 96 48 27 72 39 70 13 68 100 36 95 4 12 23 34 74 65 42 12 54 69 48 45 63 58 38 60 24 42 30 79 17 36 91 43 89 7 41 43 65 49 47 6 91 30 71 51 7 2 94 49 30 24 85 55 57 41 67 77 32 9 45 40 27 24 38 39 19 83 30 42
100
1...

output:

102
110
196
1336
57
169
625
461
9
1878
9
184
48
110
132
1
90
362
1854
256
254
254
362
651
1189
169
169
815
2178
20
654
56
344
782
627
811
784
1481
703
81
600
574
121
2042
439
1117
344
64
20
2
20
80
647
381
2357
81
342
1990
36
673
1088
42
619
442
81
90
30
629
676
783
461
304
308
1400
553
290
90
100
1...

result:

ok 100 numbers

Test #6:

score: 0
Accepted
time: 0ms
memory: 9972kb

input:

100
2 2 1 1 2 1 1 1 1 1 2 2 2 2 2 2 2 1 2 1 2 1 1 2 1 1 2 1 1 2 2 1 2 1 2 1 2 2 2 1 2 2 1 2 2 1 2 2 2 1 2 1 1 2 2 2 2 2 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 2 2 1 2 2 1 1 1 1 1 1 2 1 1 2 1 2 2 1 1 1 2 2
100
16 34
40 59
5 31
7 78
74 87
22 46
25 73
30 71
74 78
13 98
87 91
37 62
56 68
56 75
32 53
51 5...

output:

24
41
62
167
29
34
113
104
8
186
7
51
35
63
31
1
25
72
195
60
89
89
67
99
153
33
56
112
211
15
99
18
95
134
93
138
120
164
131
28
114
125
28
207
83
149
95
39
29
3
29
25
95
57
217
40
66
205
16
129
149
32
94
69
36
38
15
93
115
134
104
93
92
160
80
69
61
25
76
105
77
38
38
41
170
61
5
140
23
155
84
206...

result:

ok 100 numbers

Test #7:

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

input:

100
2 4 3 1 2 1 3 3 3 1 2 2 2 4 2 4 4 3 4 1 4 1 3 2 1 3 2 1 3 4 4 3 4 3 2 1 4 4 4 3 4 4 3 2 2 1 2 4 2 1 4 1 3 2 2 4 4 2 2 3 1 4 3 3 1 3 1 3 1 1 3 2 3 2 3 3 3 2 2 1 2 4 1 3 1 1 3 1 4 1 1 4 3 4 2 3 3 3 2 2
100
16 34
40 59
5 31
7 78
74 87
22 46
25 73
30 71
74 78
13 98
87 91
37 62
56 68
56 75
32 53
51 5...

output:

62
64
106
304
38
83
178
143
8
406
9
87
37
86
76
1
46
123
389
107
173
174
128
176
313
78
94
197
429
17
177
35
190
290
196
280
216
369
277
65
244
261
63
407
138
324
190
49
17
2
16
63
193
130
459
56
126
410
37
277
293
46
187
137
78
86
32
173
189
282
206
195
199
335
161
136
68
52
137
180
97
97
86
106
38...

result:

ok 100 numbers

Test #8:

score: 0
Accepted
time: 5ms
memory: 13828kb

input:

10000
2 4 3 1 2 1 3 3 3 1 2 2 2 4 2 4 4 3 4 1 4 1 3 2 1 3 2 1 3 4 4 3 4 3 2 1 4 4 4 3 4 4 3 2 2 1 2 4 2 1 4 1 3 2 2 4 4 2 2 3 1 4 3 3 1 3 1 3 1 1 3 2 3 2 3 3 3 2 2 1 2 4 1 3 1 1 3 1 4 1 1 4 3 4 2 3 3 3 2 2 2 4 4 3 1 3 2 3 2 3 2 2 1 1 3 2 2 2 2 1 3 3 2 1 4 4 4 3 4 1 3 3 2 1 3 3 4 4 4 2 2 4 2 4 2 2 2 ...

output:

36321
35405
1209
25190
40287
17354
4347
12364
19345
22868
33513
19988
21050
22371
4155
16423
19777
13766
36851
10463
655
21282
27833
14587
2094
7224
26214
5101
19637
12315
36315
31986
29611
4264
34081
25650
10369
10690
42069
9478
18835
5647
3738
25622
26508
8411
5704
32775
19620
23373
27204
5543
102...

result:

ok 10000 numbers

Test #9:

score: 0
Accepted
time: 11ms
memory: 13868kb

input:

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

output:

121676
121523
3628
86267
138275
58850
13317
40670
63807
74277
107841
66609
70556
74015
14448
54400
68407
44066
124066
35926
2111
68998
91062
49395
6818
27160
89176
19812
64970
38456
121158
107877
101875
14130
117171
88392
35239
34015
144173
33217
65218
20707
11384
88427
90982
26416
18798
108907
6626...

result:

ok 10000 numbers

Test #10:

score: 0
Accepted
time: 13ms
memory: 11712kb

input:

10000
42 68 35 1 70 25 79 59 63 65 6 46 82 28 62 92 96 43 28 37 92 5 3 54 93 83 22 17 19 96 48 27 72 39 70 13 68 100 36 95 4 12 23 34 74 65 42 12 54 69 48 45 63 58 38 60 24 42 30 79 17 36 91 43 89 7 41 43 65 49 47 6 91 30 71 51 7 2 94 49 30 24 85 55 57 41 67 77 32 9 45 40 27 24 38 39 19 83 30 42 34 ...

output:

2086076
1741366
11967
1193241
2110395
789795
142677
548677
887034
1186670
1761104
916514
998932
1073026
130271
816651
950616
612723
1894013
431282
5293
1061786
1388067
814119
41390
318618
1577376
209314
937347
556324
1871841
1576377
1414009
140524
1697550
1236904
665387
460557
2366910
467173
896169
...

result:

ok 10000 numbers

Test #11:

score: 0
Accepted
time: 18ms
memory: 11848kb

input:

10000
42 468 335 501 170 725 479 359 963 465 706 146 282 828 962 492 996 943 828 437 392 605 903 154 293 383 422 717 719 896 448 727 772 539 870 913 668 300 36 895 704 812 323 334 674 665 142 712 254 869 548 645 663 758 38 860 724 742 530 779 317 36 191 843 289 107 41 943 265 649 447 806 891 730 371...

output:

11554412
10707633
12445
5347584
14025479
2523856
160056
1274581
3158550
4473303
9676996
3520204
3883961
4306275
150989
2484683
3332887
1577078
11744904
966279
5331
3847822
6752488
1931344
38391
464404
6205172
249674
3378305
1255895
11134967
8854999
7618079
159796
10022680
5591698
963405
933305
15535...

result:

ok 10000 numbers

Test #12:

score: 0
Accepted
time: 13ms
memory: 11792kb

input:

10000
42 8468 6335 6501 9170 5725 1479 9359 6963 4465 5706 8146 3282 6828 9962 492 2996 1943 4828 5437 2392 4605 3903 154 293 2383 7422 8717 9719 9896 5448 1727 4772 1539 1870 9913 5668 6300 7036 9895 8704 3812 1323 334 7674 4665 5142 7712 8254 6869 5548 7645 2663 2758 38 2860 8724 9742 7530 779 231...

output:

24129088
24514134
24523544
24335849
24124639
24583022
24598013
24434757
24326327
24816819
24168451
24429742
24543587
24558374
24602958
24489071
24474276
24647678
24424942
24221826
24697217
24727161
24607980
24811837
24105079
24469296
24801840
24951537
24617800
24508898
24811923
24816800
24390196
245...

result:

ok 10000 numbers

Test #13:

score: -100
Wrong Answer
time: 572ms
memory: 114100kb

input:

500000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

755805180
-766224202
1075820325
-1741594305
-1262592670
1161740503
86796900
790545230
746066549
230416363
684129006
-200718713
-418037319
1495134507
-1260364565
1849171082
-172783495
1284924017
-1986344089
414141332
1969052616
-911665511
-741442291
175403994
-2074399569
623402081
7712628
-755084794
...

result:

wrong answer 1st numbers differ - expected: '26525608956', found: '755805180'