社区讨论

死循环代码求调!

B3874[GESP202309 六级] 小杨的握手问题参与者 3已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@mhjhwauh
此快照首次捕获于
2025/11/04 02:50
4 个月前
此快照最后确认于
2025/11/04 02:50
4 个月前
查看原帖
救救本蒟蒻吧……肝不动了……
CPP
# include <bits/stdc++.h>
# define int long long
# define endl '\n'
# define str string
# define fst ios::sync_with_stdio (0); cin.tie (0); cout.tie (0);

using namespace std;

const int N = 1e6 + 5, M = 2e6 + 5;
const int P = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int LNF = 0x3f3f3f3f3f3f3f3f;

int n;
int ans;
int t[N];
int sum;

inline int lowbit (int x) {
	return (x & (- x));
}

signed main () {
	fst;
	cin >> n;
	for (int i = 1, a; i <= n; i ++ ) {
		cin >> a;
		int x = a;
		while (a <= n) {
			t[a] ++;
			a += lowbit (a);
		} 
		sum = 0;
		while (x) {
			sum += t[x];
			x -= lowbit (x);
		}
		ans += (i - sum);
	}
	cout << ans;
	return 0;
}

回复

5 条回复,欢迎继续交流。

正在加载回复...