# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
815723 |
2023-08-08T20:06:15 Z |
exodus_ |
Ekoeko (COCI21_ekoeko) |
C++14 |
|
51 ms |
5416 KB |
#include<bits/stdc++.h>
using namespace std;
int freq[200]={0};
const int maxn = 200001;
vector<int>exclnt;
deque<int>dex[200];
vector<int>ord;
int segtree[4*maxn]={0};
void update(int idx, int low, int high, int val) {
if(low==val && high==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;
return quer(2*idx,low,mid,l,r)+quer(2*idx+1,mid+1,high,l,r);
}
int main() {
int n;
string gab;
cin >> n;
cin >> gab;
n = n*2;
for(int i=0; i<gab.size(); i++) freq[gab[i]]++;
for(int i=0; i<n; i++) {
if(freq[gab[i]] > 0) {
exclnt.push_back(gab[i]);
freq[gab[i]]-=2;
}
}
int ukex = exclnt.size();
for(int i=0; i<ukex; i++) {
exclnt.push_back(exclnt[i]);
}
for(int i=0; i<n; i++) {
dex[exclnt[i]].push_back(i);
}
for(int i=0; i<n; i++) {
ord.push_back(dex[gab[i]].front());
dex[gab[i]].pop_front();
}
int ans=0;
for(int i=0; i<n; i++) {
ans+=quer(1,1,n-1,ord[i],n-1);
update(1,1,n-1,ord[i]);
}
cout << ans << endl;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i=0; i<gab.size(); i++) freq[gab[i]]++;
| ~^~~~~~~~~~~
Main.cpp:36:48: warning: array subscript has type 'char' [-Wchar-subscripts]
36 | for(int i=0; i<gab.size(); i++) freq[gab[i]]++;
| ^
Main.cpp:38:23: warning: array subscript has type 'char' [-Wchar-subscripts]
38 | if(freq[gab[i]] > 0) {
| ^
Main.cpp:40:24: warning: array subscript has type 'char' [-Wchar-subscripts]
40 | freq[gab[i]]-=2;
| ^
Main.cpp:51:33: warning: array subscript has type 'char' [-Wchar-subscripts]
51 | ord.push_back(dex[gab[i]].front());
| ^
Main.cpp:52:19: warning: array subscript has type 'char' [-Wchar-subscripts]
52 | dex[gab[i]].pop_front();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
17 ms |
2440 KB |
Output is correct |
3 |
Correct |
36 ms |
4424 KB |
Output is correct |
4 |
Incorrect |
51 ms |
5416 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
17 ms |
2440 KB |
Output is correct |
3 |
Correct |
36 ms |
4424 KB |
Output is correct |
4 |
Incorrect |
51 ms |
5416 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
17 ms |
2440 KB |
Output is correct |
3 |
Correct |
36 ms |
4424 KB |
Output is correct |
4 |
Incorrect |
51 ms |
5416 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
17 ms |
2440 KB |
Output is correct |
3 |
Correct |
36 ms |
4424 KB |
Output is correct |
4 |
Incorrect |
51 ms |
5416 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |