QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#773413#9792. Ogre Sortucup-team5319#WA 2ms11744kbC++142.1kb2024-11-23 08:45:252024-11-23 08:45:26

Judging History

This is the latest submission verdict.

  • [2024-11-23 08:45:26]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 11744kb
  • [2024-11-23 08:45:25]
  • Submitted

answer

//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si inline
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef __int128 li;typedef long double ld;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef const int ci;typedef const ll cl;ci iinf=INT_MAX;cl linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}

namespace LinkWish{
	
	ci N=300005;

	int n,a[N];

	mt19937 R(40094229);
	struct Hoshino{
		int ls,rs,key,sz,fa,v;
		si Hoshino(){ls=rs=sz=fa=0,key=(int)R(),v=0;}
	}t[N];
	int rt;
	si void init(int id){t[id].sz=1,t[id].v=id;}
	si void push_up(int x){
		t[x].sz=t[t[x].ls].sz+t[t[x].rs].sz+1;
		if(t[x].ls!=0)t[t[x].ls].fa=x;
		if(t[x].rs!=0)t[t[x].rs].fa=x;
		t[x].fa=0;
	}
	void splits(int x,int &l,int &r,int k){
		if(x==0)return l=r=0,void();
		if(t[t[x].ls].sz>=k)r=x,splits(t[x].ls,l,t[x].ls,k);
		else l=x,splits(t[x].rs,t[x].rs,r,k-t[t[x].ls].sz-1);
		push_up(x);
	}
	int getrk(int x){
		int res=t[t[x].ls].sz+1;
		for(;t[x].fa!=0;x=t[x].fa)if(x==t[t[x].fa].rs)res+=t[t[t[x].fa].ls].sz+1;
		return res;
	}
	int merge(int x,int y){
		if(!x||!y)return x+y;
		if(t[x].key<t[y].key)return t[x].rs=merge(t[x].rs,y),push_up(x),x;
		return t[y].ls=merge(x,t[y].ls),push_up(y),y;
	}

	void mian(){
		cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i],init(a[i]),rt=merge(rt,a[i]);

		ll ans=0;
		vector<pii> op;
		for(int i=n-1;i;i--){
			int pos=getrk(i),pp=getrk(i+1);
			if(pos>pp){
				ans+=pp,op.emplace_back(pos,pp);
				int x,y,z;
				splits(rt,x,y,pos-1),splits(y,y,z,1);
				rt=merge(x,z);
				splits(rt,x,z,pp-1);
				rt=merge(merge(x,y),z);
			}
		}

		cout<<ans<<' '<<op.size()<<endl;
		for(pii i:op)cout<<i.fi<<' '<<i.se<<endl;
	}
}

signed main(){
	#ifndef ONLINE_JUDGE
	assert(freopen("in.in","r",stdin));
	assert(freopen("out.out","w",stdout));
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	LinkWish::mian();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 11744kb

input:

4
1 2 4 3

output:

3 1
4 3

result:

ok Participant's output is correct

Test #2:

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

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: 2ms
memory: 10904kb

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #4:

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

input:

4
1 2 4 3

output:

3 1
4 3

result:

ok Participant's output is correct

Test #5:

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

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: 2ms
memory: 10600kb

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #7:

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

input:

1
1

output:

0 0

result:

ok Participant's output is correct

Test #8:

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

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: 0ms
memory: 11560kb

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: 2ms
memory: 10888kb

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: 2ms
memory: 11252kb

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]