# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
815751 |
2023-08-08T20:57:00 Z |
exodus_ |
Ekoeko (COCI21_ekoeko) |
C++14 |
|
60 ms |
4492 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+1;
int segtree[4*N] = {0};
int freq[30];
vector<char>urt;
deque<int>dex[30];
vector<int>isi;
void update(int idx, int low, int high, int val) {
if(high==low && low==val) {
segtree[idx]=1;
return;
}
if(val<low || val>high) return;
int mid=(low+high)/2;
update(2*idx,low,mid,val);
update(2*idx+1,mid+1,high,val);
segtree[idx] = segtree[2*idx]+segtree[2*idx+1];
}
int quer(int idx, int low, int high, int l, int r) {
if(low>=l && high<=r) {
return segtree[idx];
}
if(low>r || high<l) return 0;
int mid = (low+high)/2;
int left = quer(2*idx,low,mid,l,r);
int right = quer(2*idx+1,mid+1,high,l,r);
return left+right;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
n*=2;
string asli;
cin >> asli;
for(int i=0; i<n; i++) {
freq[asli[i]-97]++;
}
for(int i=0; i<n; i++) {
if(freq[asli[i]-97]>0) {
urt.push_back(asli[i]);
freq[asli[i]-97]-=2;
}
}
int sizeurt=urt.size();
for(int i=0; i<sizeurt; i++) {
urt.push_back(urt[i]);
}
for(int i=0; i<n; i++) {
dex[urt[i]-97].push_back(i+1);
}
for(int i=0; i<n; i++) {
isi.push_back(dex[asli[i]-97].front());
dex[asli[i]-97].pop_front();
}
long long jwbn=0;
for(int i=0; i<n; i++) {
jwbn+=quer(1,1,n,isi[i]+1,n);
update(1,1,n,isi[i]);
}
cout << jwbn << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
15 ms |
2168 KB |
Output is correct |
3 |
Correct |
31 ms |
3804 KB |
Output is correct |
4 |
Correct |
57 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
15 ms |
2168 KB |
Output is correct |
3 |
Correct |
31 ms |
3804 KB |
Output is correct |
4 |
Correct |
57 ms |
4432 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
15 ms |
2168 KB |
Output is correct |
3 |
Correct |
31 ms |
3804 KB |
Output is correct |
4 |
Correct |
57 ms |
4432 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
53 ms |
4444 KB |
Output is correct |
7 |
Correct |
50 ms |
4492 KB |
Output is correct |
8 |
Correct |
49 ms |
4452 KB |
Output is correct |
9 |
Correct |
49 ms |
4464 KB |
Output is correct |
10 |
Correct |
48 ms |
4492 KB |
Output is correct |
11 |
Correct |
48 ms |
4436 KB |
Output is correct |
12 |
Correct |
60 ms |
4356 KB |
Output is correct |
13 |
Correct |
49 ms |
4344 KB |
Output is correct |
14 |
Correct |
46 ms |
4292 KB |
Output is correct |
15 |
Correct |
46 ms |
4360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
2 |
Correct |
15 ms |
2168 KB |
Output is correct |
3 |
Correct |
31 ms |
3804 KB |
Output is correct |
4 |
Correct |
57 ms |
4432 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
53 ms |
4444 KB |
Output is correct |
11 |
Correct |
50 ms |
4492 KB |
Output is correct |
12 |
Correct |
49 ms |
4452 KB |
Output is correct |
13 |
Correct |
49 ms |
4464 KB |
Output is correct |
14 |
Correct |
48 ms |
4492 KB |
Output is correct |
15 |
Correct |
48 ms |
4436 KB |
Output is correct |
16 |
Correct |
60 ms |
4356 KB |
Output is correct |
17 |
Correct |
49 ms |
4344 KB |
Output is correct |
18 |
Correct |
46 ms |
4292 KB |
Output is correct |
19 |
Correct |
46 ms |
4360 KB |
Output is correct |
20 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
32 |
Correct |
51 ms |
4456 KB |
Output is correct |
33 |
Correct |
51 ms |
4436 KB |
Output is correct |
34 |
Correct |
50 ms |
4480 KB |
Output is correct |
35 |
Correct |
49 ms |
4476 KB |
Output is correct |
36 |
Correct |
50 ms |
4344 KB |
Output is correct |
37 |
Correct |
48 ms |
4432 KB |
Output is correct |
38 |
Correct |
52 ms |
4428 KB |
Output is correct |
39 |
Correct |
48 ms |
4420 KB |
Output is correct |
40 |
Correct |
48 ms |
4288 KB |
Output is correct |
41 |
Correct |
47 ms |
4268 KB |
Output is correct |