QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#773514#9792. Ogre Sortucup-team3564#WA 12ms30652kbC++142.1kb2024-11-23 09:12:342024-11-23 09:12:34

Judging History

This is the latest submission verdict.

  • [2024-11-23 09:12:34]
  • Judged
  • Verdict: WA
  • Time: 12ms
  • Memory: 30652kb
  • [2024-11-23 09:12:34]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long T,a,b,c,d[1000001],v[1000001],o,h[1000001],fa[1000001],q,w,e,an,cn,fac[1000001],inv[1000001],st[1000001],u[1000001],cnn,stt[1000001],an1;
char s[1000001];
struct p{long long q,w;}l[1000001],m[1000001];
long long pow_(long long qq,long long ww){long long ee=1;while(ww){if(ww&1) ee*=qq,ee%=mod;qq*=qq,qq%=mod,ww>>=1;}return ee%mod;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
void add(long long qq,long long ww){l[++o].q=ww,l[o].w=h[qq],h[qq]=o;}
long long gcd(long long qq,long long ww){return !ww?qq:gcd(ww,qq%ww);}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
long long C(long long qq,long long ww){return fac[qq]*inv[ww]%mod*inv[qq-ww]%mod;}
bool cmp(p qq,p ww){return qq.w>ww.w;}
int lowbit(int qq){return qq&(-qq);}
void change(int qq,int ww)
{
	for(int i=qq;i<=a;i+=lowbit(i)) u[i]+=ww;
}
long long query(long long qq)
{
	long long ann=0;
	for(int i=qq;i;i-=lowbit(i)) ann+=u[i];
	return ann;
}
long long get(long long qq)
{
	return qq+query(qq);
}
int main()
{
//	freopen("1.in","r",stdin);
	srand((unsigned)(time(0)^(*new int)));
	fac[0]=1;for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%mod;
	inv[1000000]=pow_(fac[1000000],mod-2);for(int i=999999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	scanf("%lld",&a);
	for(int i=1;i<=a;i++)
	{
		scanf("%lld",&d[i]);
	}
	long long mxx=0;
	for(int i=1;i<=a;i++)
	{
		if(d[i]>mxx)
		{
			mxx=d[i];
			st[++cn]=i;
			v[i]=1;
		}
	}st[cn+1]=a+1;
	for(int i=cn;i>=1;i--)
	{
		for(int j=st[i]+1;j<=st[i+1]-1;j++)
		{
			l[++cnn]=p{j,d[j]};
		}
	}
	long long nww=cn;
	sort(l+1,l+cnn+1,cmp);
	for(int j=1;j<=cnn;j++)
	{
		while(nww>1&&l[j].w<d[st[nww-1]]) --nww;
		m[++an]=p{get(l[j].q),st[nww]};
		change(l[j].q,-1);
		change(st[nww],1);
		an1+=st[nww];
	}
	printf("%lld %lld\n",an1,an);
	for(int i=1;i<=an;i++) printf("%lld %lld\n",m[i].q,m[i].w);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 28420kb

input:

4
1 2 4 3

output:

3 1
4 3

result:

ok Participant's output is correct

Test #2:

score: 0
Accepted
time: 4ms
memory: 30620kb

input:

5
2 4 1 3 5

output:

3 2
4 2
4 1

result:

ok Participant's output is correct

Test #3:

score: 0
Accepted
time: 4ms
memory: 28556kb

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #4:

score: 0
Accepted
time: 8ms
memory: 30608kb

input:

4
1 2 4 3

output:

3 1
4 3

result:

ok Participant's output is correct

Test #5:

score: 0
Accepted
time: 8ms
memory: 28604kb

input:

5
2 4 1 3 5

output:

3 2
4 2
4 1

result:

ok Participant's output is correct

Test #6:

score: 0
Accepted
time: 8ms
memory: 28508kb

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #7:

score: 0
Accepted
time: 12ms
memory: 28492kb

input:

1
1

output:

0 0

result:

ok Participant's output is correct

Test #8:

score: 0
Accepted
time: 8ms
memory: 30652kb

input:

5
5 3 4 1 2

output:

4 4
3 1
3 1
5 1
5 1

result:

ok Participant's output is correct

Test #9:

score: 0
Accepted
time: 8ms
memory: 28564kb

input:

5
4 1 2 3 5

output:

3 3
4 1
4 1
4 1

result:

ok Participant's output is correct

Test #10:

score: 0
Accepted
time: 9ms
memory: 30516kb

input:

5
1 3 4 2 5

output:

2 1
4 2

result:

ok Participant's output is correct

Test #11:

score: -100
Wrong Answer
time: 6ms
memory: 30528kb

input:

5
1 4 5 2 3

output:

4 2
5 2
5 2

result:

wrong answer Integer parameter [name=participant answer] equals to 4, violates the range [0, 3]