UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#206655#3159. 子序列权值和marcuse100215ms11500kbC++1.3kb2024-07-23 19:33:522024-07-23 20:16:58

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100000 + 10;
const int mod = 1e9 + 7;
int n,a[N],ans;
int maxn,Tr[N * 10];
bool vis[N * 10];
int opt[N];
int read(){
	char ch; int sum = 0,flag = 1;
	ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') flag = -flag; ch = getchar();}
	while(ch >= '0' && ch <= '9'){sum = sum * 10 + ch - '0'; ch = getchar();}
	return sum * flag;
}
int query(int x){
	int sum = 0;
	while(x){
		sum = (sum + Tr[x]) % mod;
		x = x - (x & (-x));
	}
	return sum;
}
int Ask(int lft,int rgt){
	return (query(rgt) % mod + mod - query(lft - 1) % mod) % mod;
}
void Add(int x,int val){
	while(x <= maxn){
		if(val < 0)
		Tr[x] = (Tr[x] % mod - ((-val) % mod) + mod) % mod;
		else Tr[x] = (Tr[x] % mod + val % mod) % mod;
		x = x + (x & (-x));
	}
	return ;
}
signed main(){
	n = read();
	for(int i = 1; i <= n; i++){
		a[i] = read();
		maxn = max(maxn,a[i]);
	}
	for(int i = 1; i <= n; i++) opt[i] = a[i];
	for(int i = 1; i <= n; i++){
		int val = Ask(1,a[i]);
		opt[i] = (opt[i] % mod + val * a[i] % mod) % mod;
		Add(a[i],-Ask(a[i],a[i]));
		Add(a[i],opt[i]);
	}
	memset(vis,0,sizeof(vis));
	for(int i = n; i >= 1; i--){
		if(!vis[a[i]]) ans = (ans + opt[i]) % mod;
		vis[a[i]] = 1;
	}
	printf("%lld\n",ans % mod);
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 2156kb

input:

1000
424 541 861 335 870 877 663 144 505 880 285 609 593 113 78 221 275 405 479 98 926 685 808 935 3...

output:

739694155

result:

ok single line: '739694155'

Test #2:

score: 10
Accepted
time: 0ms
memory: 2156kb

input:

1000
186 234 63 100 100 109 22 52 236 91 34 41 296 136 123 109 288 39 131 244 229 71 235 240 81 104 ...

output:

303741326

result:

ok single line: '303741326'

Test #3:

score: 10
Accepted
time: 0ms
memory: 2152kb

input:

1000
384 49 79 431 201 338 447 211 151 457 255 383 93 126 261 66 381 236 137 196 186 460 94 60 213 3...

output:

797805256

result:

ok single line: '797805256'

Test #4:

score: 10
Accepted
time: 0ms
memory: 2156kb

input:

1000
234 643 445 188 622 376 228 611 380 484 369 547 292 372 503 488 397 64 308 231 281 57 91 157 56...

output:

186711353

result:

ok single line: '186711353'

Test #5:

score: 10
Accepted
time: 0ms
memory: 2172kb

input:

1000
519 2117 285 1038 2122 2246 1545 1985 1186 474 1289 2055 1321 110 2451 1862 2083 957 2222 2026 ...

output:

315508461

result:

ok single line: '315508461'

Test #6:

score: 10
Accepted
time: 28ms
memory: 3736kb

input:

100000
137 4070 2090 2523 4660 1526 3207 4171 1046 1116 4867 4092 1253 1364 1031 2607 2647 3776 3241...

output:

903318187

result:

ok single line: '903318187'

Test #7:

score: 10
Accepted
time: 38ms
memory: 4088kb

input:

100000
34252 48736 35360 3047 22753 15929 9942 40480 8287 4994 22525 11588 18829 30900 19543 5758 46...

output:

1257523

result:

ok single line: '1257523'

Test #8:

score: 10
Accepted
time: 35ms
memory: 4316kb

input:

100000
69952 3195 64351 54788 23370 45650 73568 18291 34076 62935 54813 75012 36136 53199 1251 27361...

output:

338747613

result:

ok single line: '338747613'

Test #9:

score: 10
Accepted
time: 46ms
memory: 6428kb

input:

100000
69259 13181 252946 289781 289531 160811 182875 228926 271912 259498 151136 153993 330896 2617...

output:

415605303

result:

ok single line: '415605303'

Test #10:

score: 10
Accepted
time: 68ms
memory: 11500kb

input:

100000
914126 247537 522976 194321 339086 18681 703175 524960 601806 765134 557165 11310 562071 5519...

output:

515796625

result:

ok single line: '515796625'

Extra Test:

score: 0
Extra Test Passed