QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#801639 | #9792. Ogre Sort | ucup-team1430# | WA | 0ms | 3844kb | C++20 | 2.0kb | 2024-12-07 04:34:09 | 2024-12-07 04:34:10 |
Judging History
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]--;
vi p(n); rep(i,0,n)p[v[i]] = i;
SegTree<Spec> seg(n);
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();
order.pb(x);
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]);
pq.push(v[i]); info[v[i]].first = i;
}
}
sort(all(order));
rep(i,0,sz(order))info[order[i]].second = order[i]-i, cost += order[i]-i+1;
reverse(all(order));
rep(i,0,sz(order)){
info[order[i]].first = seg.query(0,i) + p[order[i]];
seg.update(1, info[order[i]].second);
ans.pb(info[order[i]]);
}
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: 3636kb
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: 3836kb
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: 3676kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
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: 3644kb
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: 3572kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
1 1
output:
0 0
result:
ok Participant's output is correct
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3640kb
input:
5 5 3 4 1 2
output:
4 4 3 1 3 1 7 1 7 1
result:
wrong answer Integer parameter [name=participant move lside argument] equals to 7, violates the range [1, 5]