QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#801619#9792. Ogre Sortucup-team1430#WA 0ms3888kbC++201.8kb2024-12-07 04:05:582024-12-07 04:06:47

Judging History

This is the latest submission verdict.

  • [2024-12-07 04:06:47]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3888kb
  • [2024-12-07 04:05:58]
  • 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(T v, int p){
		for(seg[p+=n]=v;p/=2;)seg[p]=S::op(seg[p/2],seg[p/2+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 Spec{using T = int;
	static constexpr T id = 0;
	static T op(T a, T b){return a+b;}
};

void solve() {
	int n; cin >> n;
	vi v(n); rep(i,0,n)cin>>v[i];
	rep(i,0,n)v[i]--;
	SegTree<Spec> seg(n+1);
	vector<pii> ans; int cost=0;
	vi order;
	vector<pii> info(n);
	priority_queue<int> pq;
	for(int i = n-1, pos = n-1; i >= -1; i--){
		
		while(not pq.empty() and pq.top()==pos){
			int x = pq.top(); pq.pop();
			debug("cara descendo");
			debug(pos); debug(x);
			info[x].second = i+1; pos--;
		}
		if (i==-1)continue;
		debug("cara atual");
		debug(pos); debug(v[i]);
		if (v[i]==pos){
			debug("cara certo");
			debug(pos); debug(v[i]);
			pos--; continue;
		}
		else{
			debug("cara subindo");
			debug(pos); debug(v[i]);
			order.pb(v[i]); pq.push(v[i]); info[v[i]].first = pos;
		}
	}
	for(int x : order){
		ans.pb(info[x]); cost += info[x].second+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: 3640kb

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

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

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #4:

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

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

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

input:

3
1 2 3

output:

0 0

result:

ok Participant's output is correct

Test #7:

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

input:

1
1

output:

0 0

result:

ok Participant's output is correct

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 3580kb

input:

5
5 3 4 1 2

output:

4 4
5 1
5 1
5 1
5 1

result:

wrong answer participant's moves don't sort the array