# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
815750 |
2023-08-08T20:53:31 Z |
exodus_ |
Ekoeko (COCI21_ekoeko) |
C++14 |
|
48 ms |
4616 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() {
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);
}
for(int i=0; i<n; i++) {
isi.push_back(dex[asli[i]-97].front());
dex[asli[i]-97].pop_front();
}
int jwbn=0;
for(int i=0; i<n; i++) {
jwbn+=quer(1,0,n-1,isi[i]+1,n-1);
update(1,0,n-1,isi[i]);
}
cout << jwbn << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
2172 KB |
Output is correct |
3 |
Correct |
32 ms |
3920 KB |
Output is correct |
4 |
Incorrect |
48 ms |
4616 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
2172 KB |
Output is correct |
3 |
Correct |
32 ms |
3920 KB |
Output is correct |
4 |
Incorrect |
48 ms |
4616 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
2172 KB |
Output is correct |
3 |
Correct |
32 ms |
3920 KB |
Output is correct |
4 |
Incorrect |
48 ms |
4616 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
16 ms |
2172 KB |
Output is correct |
3 |
Correct |
32 ms |
3920 KB |
Output is correct |
4 |
Incorrect |
48 ms |
4616 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |