QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#718506#6434. Paimon Sortingnan_lingWA 0ms3648kbC++171.3kb2024-11-06 20:42:142024-11-06 20:42:17

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 20:42:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3648kb
  • [2024-11-06 20:42:14]
  • 提交

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];
	cout << ans << ' ';
	for(int i = 2; i <= n; i ++)
	{
		if(a[i] > maxn)
		{
			maxn = a[i];
			ans += 2;
			cout << ans << ' ';
			
			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: 3648kb

input:

3
5
2 3 2 1 5
3
1 2 3
1
1

output:

0 2 3 5 7 
0 2 4 
0

result:

wrong answer 1st lines differ - expected: '0 2 3 5 7', found: '0 2 3 5 7 '