QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784408 | #9792. Ogre Sort | orz_z | WA | 1ms | 8016kb | C++14 | 3.6kb | 2024-11-26 14:55:54 | 2024-11-26 14:55:57 |
Judging History
answer
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {
cerr << "[" << s << "] = [" << x << "]\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {
for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
else if (s[i] == ')' || s[i] == '}') b--;
else if (s[i] == ',' && b == 0) {
cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";
debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
break;
}
}
#ifdef orzz
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define Debug(...)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
int x = 0;
bool t = 0;
char c = getchar();
while (c < '0' || c > '9') t |= c == '-', c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return t ? -x : x;
}
inline void wi(int x) {
if (x < 0) {
putchar('-'), x = -x;
}
if (x > 9) wi(x / 10);
putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
wi(x), putchar(s);
}
bool Mbe;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int _ = 3e5 + 5;
int n, a[_], b[_], val[_];
struct Bit {
int C[_];
void clear() {
memset(C, 0, sizeof C);
}
void upd(int x, int v) {
for(; x <= n; x += x & -x) C[x] += v;
}
int qry(int x) {
int res = 0;
for(; x; x -= x & -x) res += C[x];
return res;
}
} C;
bool flg[_];
struct node {
int a, b, c;
};
bool Med;
signed main() {
// Mry;
n = ri();
ll ans = 0;
vector<node> Rs;
F(i, 1, n) a[i] = ri(), b[a[i]] = i;
F(i, 1, n) {
int pos = C.qry(b[i]) + b[i];
Debug(i, pos, b[i], C.qry(b[i]));
if(pos == i) {
continue;
} else {
Debug(i);
flg[b[i]] = 1; // 这个值
C.upd(1, 1);
C.upd(b[i] + 1, -1);
}
}
C.clear();
dF(i, n, 1) if(flg[i]) {
val[i] = C.qry(n) - C.qry(a[i]);
Debug(i, val[i]);
C.upd(a[i], 1);
}
C.clear();
F(i, 1, n) {
if(!flg[i]) {
C.upd(a[i], 1);
} else {
Rs.pb((node){a[i], i + val[i], C.qry(a[i]) + 1});
ans += C.qry(a[i]) + 1;
}
}
sort(Rs.begin(), Rs.end(), [&](node a, node b) { return a.a > b.a;});
cout << ans << ' ' << Rs.size() << '\n';
for(node v : Rs) cout << v.b << ' ' << v.c << '\n';
cout << '\n';
// Try;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6148kb
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: 6756kb
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: 1ms
memory: 6896kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 8016kb
input:
4 1 2 4 3
output:
3 1 4 3
result:
ok Participant's output is correct
Test #5:
score: 0
Accepted
time: 1ms
memory: 7048kb
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: 1ms
memory: 6372kb
input:
3 1 2 3
output:
0 0
result:
ok Participant's output is correct
Test #7:
score: 0
Accepted
time: 1ms
memory: 6164kb
input:
1 1
output:
0 0
result:
ok Participant's output is correct
Test #8:
score: 0
Accepted
time: 1ms
memory: 6764kb
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: 1ms
memory: 6700kb
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: 1ms
memory: 6984kb
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: 1ms
memory: 6756kb
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]