Submission #866478

# Submission time Handle Problem Language Result Execution time Memory
866478 2023-10-26T08:44:04 Z TAhmed33 Ekoeko (COCI21_ekoeko) C++
0 / 110
1000 ms 464 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 25;
struct bit {
	int tree[MAXN];
	void add (int x) {
		for (; x < MAXN; x += x & (-x)) tree[x]++;
	}
	int get (int x) {
		int sum = 0; for (; x; x -= x & (-x)) sum += tree[x];
		return sum;
	}
} cur;
int n;
string s;
deque <int> occ[26];
int main () {
	cin >> n >> s;
	s = '0' + s; 
	for (int i = 1; i <= n; i++) occ[s[i] - 'a'].push_back(i);
	long long cnt = 0;
	for (int i = n + 1; i <= 2 * n; i++) {
		int u = occ[s[i] - 'a'].front();
		occ[s[i] - 'a'].pop_front();
		cnt += cur.get(u); cur.add(u);
	}
	cout << n * (n - 1) / 2 - cnt << '\n';
}
/*aabcdffa
adaffacb

1,2,3,4,5,6,7,8
1,5,2,6,7,8,4,3*/
# Verdict Execution time Memory Grader output
1 Execution timed out 1032 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1032 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1032 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 464 KB Output is correct
2 Execution timed out 1074 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1032 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -