QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725270#9604. Cyberangellotus_f0 0ms30288kbC++141.6kb2024-11-08 16:55:162024-11-08 16:55:16

Judging History

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

  • [2024-11-08 16:55:16]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:30288kb
  • [2024-11-08 16:55:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
int a[1000010];
int tot=0,lsh[1000010];
vector<int> vec[1000010];
int l[1000010],r[1000010];
signed main()
{
	cin>>n>>m; lsh[++tot]=m+1;
	for(int i=1; i<=n; ++i) cin>>a[i],lsh[++tot]=a[i];
	sort(lsh+1,lsh+tot+1),tot=unique(lsh+1,lsh+tot+1)-lsh-1;
	for(int i=1; i<=n; ++i) vec[lower_bound(lsh+1,lsh+tot+1,a[i])-lsh].push_back(i);
	int sum=0;
	for(int i=1; i<=n; ++i) l[i]=1,r[i]=i,a[i]=tot,sum+=lsh[a[i]]*(i-l[i]+1)*(r[i]-i+1);
	int ans=0;
	for(int i=tot; i>=1; --i)
	{
		int sum1=sum;
		for(int j:vec[i])
		{
			for(int k=1; k<j; ++k)
			{
				sum-=lsh[a[k]]*(k-l[k]+1)*(r[k]-k+1);
				r[k]=min(r[k],j-1);
				sum+=lsh[a[k]]*(k-l[k]+1)*(r[k]-k+1);
			}
			for(int k=j+1; k<=n; ++k)
			{
				sum-=lsh[a[k]]*(k-l[k]+1)*(r[k]-k+1);
				l[k]=max(l[k],j+1);
				sum+=lsh[a[k]]*(k-l[k]+1)*(r[k]-k+1);
			}
		}
		for(int j=0; j<vec[i].size(); ++j)
		{
			int wz=vec[i][j];
			sum-=lsh[a[wz]]*(wz-l[wz]+1)*(r[wz]-wz+1);
			l[wz]=1,r[wz]=(j==vec[i].size()-1?n:vec[i][j+1]-1),a[wz]=i;
			sum+=lsh[a[wz]]*(wz-l[wz]+1)*(r[wz]-wz+1);
		}
		int sum2=sum;
		for(int j:vec[i]) sum2-=lsh[a[j]]*(j-l[j]+1)*(r[j]-j+1);
		int cnt=(n+1)*n/2,lst=0;
		for(int j:vec[i]) cnt-=(j-lst)*(j-lst-1)/2,lst=j;
		cnt-=(n-lst+1)*(n-lst)/2;
		ans+=lsh[i]*(sum1-sum2-cnt*lsh[i]);
//		cout<<"sum: "<<sum1<<' '<<sum2<<' '<<cnt<<' '<<ans<<'\n';
//		cout<<"a:\n";
//		for(int j=1; j<=n; ++j) cout<<lsh[a[j]]<<' '; cout<<'\n';
//		for(int j=1; j<=n; ++j) cout<<l[j]<<' '<<r[j]<<'\n';
	}
	cout<<ans;
	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: 0ms
memory: 30288kb

input:

500 995106803
150608560 532482040 23208958 442246216 2917205 948292264 962672628 610596054 69010421 206923685 605381259 560683057 374135360 323257595 224120348 773540778 414928542 327812091 524797091 241525558 228068400 618957683 365266079 992727350 87923118 536412424 557677355 392087162 158151043 2...

output:

-4827947903610509811

result:

wrong answer 1st lines differ - expected: '59854856571283884484109', found: '-4827947903610509811'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

1000000 2
2 1 1 1 2 2 2 2 2 2 2 1 2 2 1 1 1 2 2 2 2 1 2 2 1 2 1 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 1 1 2 1 1 1 2 1 1 1 2 2 2 2 2 2 1 1 2 1 1 2 2 2 2 2 1 1 2 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 2 2 1 2 1 2 2 2 1 1 2 2 1 1 2 2 1 1 1 1 1 2 ...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Time Limit Exceeded

Test #41:

score: 0
Time Limit Exceeded

input:

500000 999997472
323565887 829841159 316294741 207123786 197822285 87425904 283234947 457350978 346818392 59983222 782455248 784568068 729477373 116544863 669509195 402486856 202576480 122339471 760623311 842345622 481616662 856729905 50173442 129883284 52084768 196396910 320675364 895095006 6623157...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%