比赛 |
NOIP模拟赛1 |
评测结果 |
AAAAAAAAAA |
题目名称 |
叉叉 |
最终得分 |
100 |
用户昵称 |
Tony |
运行时间 |
0.070 s |
代码语言 |
C++ |
内存使用 |
1.02 MiB |
提交时间 |
2018-02-08 19:35:55 |
显示代码纯文本
#include<iostream>
#include<cstring>
#include<cstdio>
#define lowbit(i) ((i)&(-i))
using namespace std;
const int maxn = 100000;
int first[maxn];
int A[maxn];
int c[maxn];
void update(int x,int v){
for(int i = x;i < maxn;i += lowbit(i)){
c[i] += v;
}
}
int getsum(int x){
int sum = 0;
for(int i = x;i > 0;i -= lowbit(i)){
sum += c[i];
}
return sum;
}
int main(){
freopen("xxxx.in","r",stdin);
freopen("xxxx.out","w",stdout);
char c[maxn];
cin>>c;
int len = strlen(c);
int cnt;
for(int i = 1;i <= len;i++){
int tb = c[i - 1] - 'a';
if(first[tb] == 0){
first[tb] = i;
update(i,1);
}
else{
cnt += (getsum(i - 1) - getsum(first[tb]));
update(first[tb],-1);
first[tb] = 0;
}
}
cout<<cnt<<endl;
fclose(stdin);
fclose(stdout);
return 0;
}