QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#801702#9792. Ogre Sortucup-team1430#WA 0ms3872kbC++201.9kb2024-12-07 05:48:452024-12-07 05:48:45

Judging History

This is the latest submission verdict.

  • [2024-12-07 05:48:45]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3872kb
  • [2024-12-07 05:48:45]
  • Submitted

answer

#include<bits/stdc++.h>

#define int long long
#define endl '\n'
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cout << #x << ": " << x << endl
#define sz(x) (int)((x).size())
#define all(x) x.begin(), x.end()
#define esp ' '
#define pii pair<int,int>
#define vi vector<int>

using namespace std;

template<class S>
struct SegTree{ using T = S::T;
	int n; vector<T> seg;
	SegTree(int s):n(s),seg(2*n,S::id){}
	void update_set(T v, int p){
		for(seg[p+=n]=v;p/=2;)seg[p]=S::op(seg[2*p],seg[2*p+1]);
	}
	void update_soma(T v, int p){
		for(seg[p+=n]+=v;p/=2;)seg[p]=S::op(seg[2*p],seg[2*p+1]);
	}
	T query(int l, int r){
		T vl=S::id, vr=S::id;
		for(l+=n,r+=n+1;l<r;l/=2,r/=2){
			if (l&1)vl = S::op(vl, seg[l++]);
			if (r&1)vr = S::op(seg[--r], vr);
		}
		return S::op(vl, vr);
	}
};

struct Soma{using T = int;
	static constexpr T id = 0;
	static T op(T a, T b){return a+b;}
};


struct Max{using T = int;
	static constexpr T id = -1;
	static T op(T a, T b){return max(a, b);}
};

void solve() {
	int n; cin >> n;
	vi v(n); rep(i,0,n)cin>>v[i];
	rep(i,0,n)v[i]--;
	vi p(n); rep(i,0,n)p[v[i]] = i;
	SegTree<Soma> seg_soma(n);
	SegTree<Max> seg_max(n);
	vector<pii> ans; int cost=0;
	vi pref = {v[0]};
	rep(i,1,n){
		if (v[i] > pref.back())pref.pb(v[i]);
		else{
			//debug(v[i]); debug(i);
			seg_max.update_set(v[i], i);
		}
	}
	rep(i,0,n-sz(pref)){
		int x = seg_max.query(0, n-1);
		int u = *upper_bound(all(pref), x);
		//debug(x); debug(p[x]); debug(u);
		int vai = p[u];
		int sai = p[x] + seg_soma.query(0, p[x]);
		seg_soma.update_soma(1, p[u]);
		seg_soma.update_soma(-1, p[x]);
		seg_max.update_set(-1, p[x]);
		ans.pb({sai, vai}); cost += vai+1;
	}
	cout << cost << esp << sz(ans) << endl;
	for(auto [a, b] : ans)cout << a+1 << esp << b+1 << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);cin.tie(0);

	int t=1;
	//cin>>t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 2 4 3

output:

3 1
4 3

result:

ok Participant's output is correct

Test #2:

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

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

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #4:

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

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: 3816kb

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

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #7:

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

input:

1
1

output:

0 0

result:

ok Participant's output is correct

Test #8:

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

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: 3584kb

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

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

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]