QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#801695 | #9792. Ogre Sort | ucup-team1430# | WA | 0ms | 3872kb | C++20 | 1.9kb | 2024-12-07 05:36:43 | 2024-12-07 05:36:44 |
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;
constexpr int oo = -1e9;
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 = 0;
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+1);
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]+1);
seg_max.update_set(0, 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: 3872kb
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: 3572kb
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: 3524kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3640kb
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: 3528kb
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: 3644kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 1
output:
0 0
result:
ok Participant's output is correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3640kb
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: 3576kb
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: 3528kb
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: 3524kb
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]