QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#783834 | #9792. Ogre Sort | ucup-team2172# | WA | 0ms | 4072kb | C++23 | 1.2kb | 2024-11-26 11:58:39 | 2024-11-26 11:58:40 |
Judging History
answer
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
int ch = 0, f = 0; x = 0;
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
if(f) x = -x;
}
using namespace __gnu_pbds;
template <class T>
using Oset = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
int main(){
int n; read(n);
vector<ll> pos(n + 1);
Oset<ll> S;
for(int i = 1, x; i <= n; i++){
read(x);
S.insert(pos[x] = 1ll * i * n);
}
ll cost = 0; vector<pair<int, int> > vec;
for(int i = n - 1; i >= 1; i--) if(pos[i] > pos[i+1]){
int rkx = (int) S.order_of_key(pos[i]) + 1;
int rky = (int) S.order_of_key(pos[i+1]) + 1;
cost += rky;
vec.push_back({rkx, rky});
S.erase(pos[i]);
S.insert(pos[i] = pos[i+1] - 1);
}
printf("%lld %d\n", cost, (int) vec.size());
for(auto [x, y] : vec) printf("%d %d\n", x, y);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3736kb
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: 3732kb
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: 4072kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3708kb
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: 3796kb
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: 3804kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
1 1
output:
0 0
result:
ok Participant's output is correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3800kb
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: 3700kb
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: 3712kb
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: 4072kb
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]