QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#718543 | #6434. Paimon Sorting | nan_ling | WA | 0ms | 3624kb | C++17 | 1.3kb | 2024-11-06 20:47:42 | 2024-11-06 20:47:42 |
Judging History
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define fixed(s) fixed<<setprecision(12)<<s
//#define int long long
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
typedef pair<ll, PII> PLII;
const int N = 100010;
int n;
int a[N];
int tr[N];
bool st[N];
int lowbit(int x)
{
return x & -x;
}
void add(int x, int c)
{
for(int i = x; i <= n; i += lowbit(i))
tr[i] += c;
}
int sum(int x)
{
int res = 0;
for(int i = x; i; i -= lowbit(i))
res += tr[i];
return res;
}
void solve()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
st[i] = 0, tr[i] = 0;
}
if(n == 1)
{
cout << 0 << endl;
return;
}
ll ans = 0;
int maxn = a[1];
add(a[1], 1);
cout << ans << ' ';
for(int i = 2; i <= n; i ++)
{
if(a[i] > maxn)
{
maxn = a[i];
ans += 2;
cout << ans;
if(i < n)cout << ' ';
if(!st[a[i]])
{
st[a[i]] = 1;
add(a[i], 1);
}
continue;
}
int t = sum(n) - sum(a[i]);
ans += t;
cout << ans;
if(i < n)cout << ' ';
if(!st[a[i]])
{
st[a[i]] = 1;
add(a[i], 1);
}
}
cout << endl;
}
int main()
{
IOS
int _;
cin >> _;
while(_ --)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
3 5 2 3 2 1 5 3 1 2 3 1 1
output:
0 2 3 6 8 0 2 4 0
result:
wrong answer 1st lines differ - expected: '0 2 3 5 7', found: '0 2 3 6 8'