QOJ.ac

QOJ

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

Judging History

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

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

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'