QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#113285#6626. Real Mountainseyiigjkn3 5ms20208kbC++142.2kb2023-06-16 21:21:502023-06-16 21:21:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-16 21:21:51]
  • 评测
  • 测评结果:3
  • 用时:5ms
  • 内存:20208kb
  • [2023-06-16 21:21:50]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int mod=1e6+3;
int ans=0,a[1000010],b[1000010],X[1000010],mx1[1000010],mx2[1000010],le[1000010],ri[1000010],f[1000010][20],g[1000010][20],N;
set<int> st;
struct Event
{
	int v,x;
	Event()=default;
	Event(int v,int x):v(v),x(x){}
	bool operator<(const Event &t)const{return v<t.v;}
}c[2000010];
int calc(int l,int r){return (ll)(l+r)*(r-l+1)/2%mod;}
void add(int &x,const auto &y){x=(x+y)%mod;}
int Qpre(int x,int v)// [1,x] : >=v
{
	if(le[v]<=x) return v;
	for(int i=__lg(N-v+1);i;i--)
		if(f[v][i] && le[f[v][i]]>x)
			v=f[v][i];
	return f[v][0];
}
int Qsuf(int x,int v)// [x,n] : >=v
{
	if(ri[v]>=x) return v;
	for(int i=__lg(N-v+1);i;i--)
		if(g[v][i] && ri[g[v][i]]<x)
			v=g[v][i];
	return g[v][0];
}
void work(int L,int R)
{
	int sz=st.size();
	if(!sz) return;
	int l=*st.begin(),r=*st.rbegin(),L1=X[Qpre(l-1,L+1)],L2=X[Qsuf(l+1,L+1)],R1=X[Qpre(r-1,L+1)],R2=X[Qsuf(r+1,L+1)];
	if(sz==1) add(ans,(ll)(L1+L2)*(X[R]-X[L])+calc(X[L],X[R]-1));
	else add(ans,(2ll*sz-3+L1+R2+min(L2,R1))*(X[R]-X[L])+3ll*(sz-1)*calc(X[L],X[R]-1));
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int n,tot=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],X[i]=a[i];
	sort(X+1,X+n+1);
	N=unique(X+1,X+n+1)-X-1;
	for(int i=1;i<=n;i++) b[i]=lower_bound(X+1,X+N+1,a[i])-X;
	for(int i=n;i;i--) le[b[i]]=i;
	for(int i=1;i<=n;i++) ri[b[i]]=i;
	int tp=0;
	static int stk[1000010];
	for(int i=N;i;i--)
	{
		while(tp && le[stk[tp]]>le[i]) tp--;
		f[i][0]=stk[tp];stk[++tp]=i;
		for(int j=1;(1<<j)<=N-i;j++) f[i][j]=f[f[i][j-1]][j-1];
	}
	tp=0;
	for(int i=N;i;i--)
	{
		while(tp && ri[stk[tp]]<ri[i]) tp--;
		g[i][0]=stk[tp];stk[++tp]=i;
		for(int j=1;(1<<j)<=N-i;j++) g[i][j]=g[g[i][j-1]][j-1];
	}
	for(int i=1;i<=n;i++) mx1[i]=max(mx1[i-1],b[i]);
	for(int i=n;i;i--) mx2[i]=max(mx2[i+1],b[i]);
	for(int i=1;i<=n;i++)
		if(b[i]<min(mx1[i],mx2[i]))
			c[++tot]=Event(b[i],i),c[++tot]=Event(min(mx1[i],mx2[i]),-i);
	sort(c+1,c+tot+1);
	for(int i=1,j=1;i<=N;i++)
	{
		if(i>1) work(i-1,i);
		for(;j<=tot && c[j].v<=i;j++)
			if(c[j].x>0) st.insert(c[j].x);
			else st.erase(-c[j].x);
	}
	cout<<ans<<"\n";
	return 0;
}

详细

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 1ms
memory: 17916kb

input:

3
29 9 9

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 2ms
memory: 17800kb

input:

3
62 20 71

output:

7287

result:

ok 1 number(s): "7287"

Test #3:

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

input:

10
72 33 22 22 13 49 53 57 72 85

output:

40403

result:

ok 1 number(s): "40403"

Test #4:

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

input:

5000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 97 97 97 97 9...

output:

481053

result:

ok 1 number(s): "481053"

Test #5:

score: 0
Accepted
time: 2ms
memory: 19976kb

input:

5000
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 1...

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 2ms
memory: 20020kb

input:

5000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:

12595

result:

ok 1 number(s): "12595"

Test #7:

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

input:

5000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...

output:

299

result:

ok 1 number(s): "299"

Test #8:

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

input:

5000
100 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:

224232

result:

ok 1 number(s): "224232"

Test #9:

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

input:

5000
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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4...

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 3ms
memory: 17828kb

input:

5000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 9...

output:

0

result:

ok 1 number(s): "0"

Test #11:

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

input:

5000
100 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4...

output:

499735

result:

ok 1 number(s): "499735"

Test #12:

score: 0
Accepted
time: 2ms
memory: 20072kb

input:

5000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 9...

output:

461407

result:

ok 1 number(s): "461407"

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #13:

score: 0
Wrong Answer
time: 2ms
memory: 18152kb

input:

5000
37 39 93 78 85 71 59 21 57 96 61 59 23 16 57 90 13 59 85 70 62 67 78 97 16 60 8 48 28 53 4 24 1 97 97 98 57 87 96 91 74 54 100 76 86 86 46 39 100 57 70 76 73 55 84 93 64 6 84 39 75 94 30 15 3 31 11 34 27 10 6 81 30 76 60 9 4 47 1 88 17 71 61 30 19 10 4 57 79 37 22 74 84 8 91 58 15 45 7 98 32 46...

output:

216205

result:

wrong answer 1st numbers differ - expected: '216624', found: '216205'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%