Submission #815743

# Submission time Handle Problem Language Result Execution time Memory
815743 2023-08-08T20:32:13 Z hohoho Ekoeko (COCI21_ekoeko) C++14
110 / 110
59 ms 7500 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = (1e5 + 5) * 2;
 
int n, cnt[26];
long long ans;
 
string str;
 
vector<char> strv;
 
vector<int> indx[26], v;
 
void up(int* Tree, int index, int s, int e, int num)
{
   
    if (s == num and e == num) {
        Tree[index] = 1;
        return;
    }
 
    if (num < s or num > e) {
        return;
    }
 
    int mid = (s + e) >> 1;
    up(Tree, 2 * index, s, mid, num);
    up(Tree, 2 * index + 1, mid + 1, e, num);
 
    Tree[index] = Tree[2 * index] + Tree[2 * index + 1];
}
 
int query(int* Tree, int index, int s,
          int e, int qs, int qe)
{
    
    if (qs <= s and e <= qe) {
        return Tree[index];
    }
 
    
    if (s > qe or e < qs) {
        return 0;
    }
 
    int mid = (s + e) >> 1;
 
    return query(Tree, 2 * index, s,
                 mid, qs, qe)
           + query(Tree, 2 * index + 1,
                   mid + 1, e, qs, qe);
}
 
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
 
    cin >> n;
    cin >> str;
 
    n *= 2;
 
    for(auto c : str) cnt[c - 'a']++;
 
    for(int i = 0; i < n; i++){
        if(cnt[str[i] - 'a'] > 0){
            strv.push_back(str[i]);
            cnt[str[i] - 'a'] -= 2;
        }
    }
 
    for(int i = 0, m = strv.size(); i < m; i++) strv.push_back(strv[i]);
 
    for(int i = 0; i < n; i++) indx[strv[i] - 'a'].push_back(i + 1);
 
    for(int i = 0; i < 26; i++) reverse(indx[i].begin(), indx[i].end());
    int mx=0;
    for(int i = 0; i < n; i++){
        v.push_back(indx[str[i] - 'a'].back());
        indx[str[i] - 'a'].pop_back();
        mx = max(mx, v[i]);
    }
    int Tree[6 * mx];
     memset(Tree, 0, sizeof(Tree));
    for(auto i : v){
        ans += query(Tree, 1, 1, mx, i + 1, mx);
        up(Tree, 1, 1, mx, i);
    }
 
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 2876 KB Output is correct
3 Correct 32 ms 4828 KB Output is correct
4 Correct 48 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 2876 KB Output is correct
3 Correct 32 ms 4828 KB Output is correct
4 Correct 48 ms 7004 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 2876 KB Output is correct
3 Correct 32 ms 4828 KB Output is correct
4 Correct 48 ms 7004 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 51 ms 7468 KB Output is correct
7 Correct 50 ms 7500 KB Output is correct
8 Correct 51 ms 7380 KB Output is correct
9 Correct 49 ms 7272 KB Output is correct
10 Correct 59 ms 7332 KB Output is correct
11 Correct 56 ms 7156 KB Output is correct
12 Correct 48 ms 7124 KB Output is correct
13 Correct 48 ms 7124 KB Output is correct
14 Correct 47 ms 6996 KB Output is correct
15 Correct 48 ms 6908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 2876 KB Output is correct
3 Correct 32 ms 4828 KB Output is correct
4 Correct 48 ms 7004 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 51 ms 7468 KB Output is correct
11 Correct 50 ms 7500 KB Output is correct
12 Correct 51 ms 7380 KB Output is correct
13 Correct 49 ms 7272 KB Output is correct
14 Correct 59 ms 7332 KB Output is correct
15 Correct 56 ms 7156 KB Output is correct
16 Correct 48 ms 7124 KB Output is correct
17 Correct 48 ms 7124 KB Output is correct
18 Correct 47 ms 6996 KB Output is correct
19 Correct 48 ms 6908 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 320 KB Output is correct
32 Correct 52 ms 7444 KB Output is correct
33 Correct 51 ms 7492 KB Output is correct
34 Correct 50 ms 7352 KB Output is correct
35 Correct 51 ms 7352 KB Output is correct
36 Correct 49 ms 7252 KB Output is correct
37 Correct 49 ms 7252 KB Output is correct
38 Correct 48 ms 7124 KB Output is correct
39 Correct 48 ms 7060 KB Output is correct
40 Correct 48 ms 6996 KB Output is correct
41 Correct 47 ms 6964 KB Output is correct