Submission #924884

# Submission time Handle Problem Language Result Execution time Memory
924884 2024-02-10T02:42:57 Z 8pete8 Ekoeko (COCI21_ekoeko) C++17
110 / 110
10 ms 9436 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<cassert>
#include<limits.h>
#include<cmath>
#include<set>
#include<numeric> //gcd(a,b)
#include<algorithm>
#include<bitset> 
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
const int mod=1e9+7,mxn=2e5+5,lg=30,inf=1e18,minf=-1e18,Mxn=100000,root=700;
void setIO(string name){		
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);		
	freopen((name+".out").c_str(),"w",stdout);	
}	
int n,m,x,y;
vector<int>adj[mxn+10];
int cnt[26],ccnt[26];
queue<int>pos[26];
struct fen{
	int fwk[mxn+10];
	void update(int pos,int val){for(int i=pos;i<=n;i+=(i&-i))fwk[i]+=val;}
	int qry(int pos){
		int sum=0;
		for(int i=pos;i>0;i-=(i&-i))sum+=fwk[i];
		return sum;
	}
}t;
int32_t main(){
	//setIO("mooriokart");
	fastio
	cin>>n;
	string a;cin>>a;
	for(auto i:a)cnt[i-'a']++;
	int ans=0;
	vector<int>v,o;
	int diff=0;
	v.pb(69);
	for(int i=0;i<n*2;i++){
		if(ccnt[a[i]-'a']>=cnt[a[i]-'a']/2)v.pb(a[i]-'a');
		else ans+=(i-diff),diff++,o.pb(a[i]-'a');
		ccnt[a[i]-'a']++;
	}
	for(int i=1;i<=n;i++)t.update(i,1),pos[v[i]].push(i);
	for(auto i:o){
		ans+=t.qry(pos[i].front())-1;
		t.update(pos[i].front(),-1);
		pos[i].pop();
	}
	cout<<ans;

}

Compilation message

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:36:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:37:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 3 ms 7576 KB Output is correct
3 Correct 6 ms 8412 KB Output is correct
4 Correct 7 ms 9432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 3 ms 7576 KB Output is correct
3 Correct 6 ms 8412 KB Output is correct
4 Correct 7 ms 9432 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 3 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 3 ms 7576 KB Output is correct
3 Correct 6 ms 8412 KB Output is correct
4 Correct 7 ms 9432 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 10 ms 9436 KB Output is correct
7 Correct 8 ms 9436 KB Output is correct
8 Correct 9 ms 9436 KB Output is correct
9 Correct 8 ms 9372 KB Output is correct
10 Correct 8 ms 9432 KB Output is correct
11 Correct 8 ms 9432 KB Output is correct
12 Correct 8 ms 9176 KB Output is correct
13 Correct 8 ms 9180 KB Output is correct
14 Correct 8 ms 9180 KB Output is correct
15 Correct 8 ms 9176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6508 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6600 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 3 ms 7576 KB Output is correct
3 Correct 6 ms 8412 KB Output is correct
4 Correct 7 ms 9432 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 3 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 10 ms 9436 KB Output is correct
11 Correct 8 ms 9436 KB Output is correct
12 Correct 9 ms 9436 KB Output is correct
13 Correct 8 ms 9372 KB Output is correct
14 Correct 8 ms 9432 KB Output is correct
15 Correct 8 ms 9432 KB Output is correct
16 Correct 8 ms 9176 KB Output is correct
17 Correct 8 ms 9180 KB Output is correct
18 Correct 8 ms 9180 KB Output is correct
19 Correct 8 ms 9176 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6508 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6600 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 8 ms 9436 KB Output is correct
33 Correct 9 ms 9436 KB Output is correct
34 Correct 8 ms 9436 KB Output is correct
35 Correct 8 ms 9436 KB Output is correct
36 Correct 8 ms 9436 KB Output is correct
37 Correct 8 ms 9436 KB Output is correct
38 Correct 8 ms 9396 KB Output is correct
39 Correct 8 ms 9180 KB Output is correct
40 Correct 8 ms 9104 KB Output is correct
41 Correct 8 ms 9180 KB Output is correct