# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
528893 | 2022-02-21T17:20:16 Z | Rafi22 | Ekoeko (COCI21_ekoeko) | C++14 | 11 ms | 3648 KB |
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define ll long long ll mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; const int N=200007; vector<int>V[200]; int side[N]; int p[N]; int BIT[N]; int que(int x) { int s=0; for (;x;x-=x&-x) s+=BIT[x]; return s; } void ins(int x,int s) { for (;x<=200000;x+=x&-x) BIT[x]+=s; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; string s; cin>>s; s='#'+s; for(int i=1;i<=2*n;i++) V[s[i]].pb(i); for(int i='a';i<='z';i++) { for(int j=0;j<sz(V[i])/2;j++) side[V[i][j]]=1; for(int j=sz(V[i])/2;j<sz(V[i]);j++) side[V[i][j]]=2; } ll ans=0,cnt=0; for(int i=1;i<=2*n;i++) { if(side[i]==2) { cnt++; p[i]=cnt; } else ans+=cnt; } for(int i='a';i<='z';i++) { for(int j=0;j<sz(V[i])/2;j++) p[V[i][j]]=p[V[i][j+sz(V[i])/2]]; } for(int i=1;i<=2*n;i++) { if(side[i]==2) continue; ans+=(ll)que(n)-que(p[i]); ins(p[i],1); } cout<<ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 324 KB | Output is correct |
2 | Correct | 3 ms | 1480 KB | Output is correct |
3 | Correct | 5 ms | 2516 KB | Output is correct |
4 | Correct | 7 ms | 3604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 324 KB | Output is correct |
2 | Correct | 3 ms | 1480 KB | Output is correct |
3 | Correct | 5 ms | 2516 KB | Output is correct |
4 | Correct | 7 ms | 3604 KB | Output is correct |
5 | Correct | 1 ms | 324 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 324 KB | Output is correct |
2 | Correct | 3 ms | 1480 KB | Output is correct |
3 | Correct | 5 ms | 2516 KB | Output is correct |
4 | Correct | 7 ms | 3604 KB | Output is correct |
5 | Correct | 1 ms | 328 KB | Output is correct |
6 | Correct | 8 ms | 3572 KB | Output is correct |
7 | Correct | 8 ms | 3568 KB | Output is correct |
8 | Correct | 9 ms | 3648 KB | Output is correct |
9 | Correct | 11 ms | 3620 KB | Output is correct |
10 | Correct | 9 ms | 3484 KB | Output is correct |
11 | Correct | 8 ms | 3492 KB | Output is correct |
12 | Correct | 8 ms | 3484 KB | Output is correct |
13 | Correct | 7 ms | 3488 KB | Output is correct |
14 | Correct | 7 ms | 3360 KB | Output is correct |
15 | Correct | 7 ms | 3364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 324 KB | Output is correct |
2 | Correct | 1 ms | 324 KB | Output is correct |
3 | Correct | 1 ms | 460 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 432 KB | Output is correct |
9 | Correct | 0 ms | 324 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 324 KB | Output is correct |
2 | Correct | 3 ms | 1480 KB | Output is correct |
3 | Correct | 5 ms | 2516 KB | Output is correct |
4 | Correct | 7 ms | 3604 KB | Output is correct |
5 | Correct | 1 ms | 324 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 0 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 328 KB | Output is correct |
10 | Correct | 8 ms | 3572 KB | Output is correct |
11 | Correct | 8 ms | 3568 KB | Output is correct |
12 | Correct | 9 ms | 3648 KB | Output is correct |
13 | Correct | 11 ms | 3620 KB | Output is correct |
14 | Correct | 9 ms | 3484 KB | Output is correct |
15 | Correct | 8 ms | 3492 KB | Output is correct |
16 | Correct | 8 ms | 3484 KB | Output is correct |
17 | Correct | 7 ms | 3488 KB | Output is correct |
18 | Correct | 7 ms | 3360 KB | Output is correct |
19 | Correct | 7 ms | 3364 KB | Output is correct |
20 | Correct | 1 ms | 324 KB | Output is correct |
21 | Correct | 1 ms | 324 KB | Output is correct |
22 | Correct | 1 ms | 460 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 332 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 432 KB | Output is correct |
28 | Correct | 0 ms | 324 KB | Output is correct |
29 | Correct | 1 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 332 KB | Output is correct |
31 | Correct | 1 ms | 332 KB | Output is correct |
32 | Correct | 8 ms | 3604 KB | Output is correct |
33 | Correct | 8 ms | 3604 KB | Output is correct |
34 | Correct | 9 ms | 3608 KB | Output is correct |
35 | Correct | 7 ms | 3500 KB | Output is correct |
36 | Correct | 8 ms | 3484 KB | Output is correct |
37 | Correct | 9 ms | 3612 KB | Output is correct |
38 | Correct | 8 ms | 3616 KB | Output is correct |
39 | Correct | 8 ms | 3500 KB | Output is correct |
40 | Correct | 7 ms | 3412 KB | Output is correct |
41 | Correct | 8 ms | 3436 KB | Output is correct |