• 欢迎光临~

# (T1 text{Part})

## 代码

``````
int n;
int a[maxm],vis[maxm];
int cnt;
int main(){
for(int i=1;i<=n;i++){
}
for(int i=n;i>=1;i--){
if(!vis[a[i]-1]){
cnt++;
}
else{
vis[a[i]-1]--;
}
vis[a[i]]++;
}
printf("%dn",cnt);
return 0;
}
``````

# (T2 text{Seq})

## 思路

[sum_r-sum_{l-1}ge (r-l+1)times P ]

[sum_r - rtimes Pge sum_{l-1} - (l-1)times P ]

## 代码

``````int n;
ll ans;
ll a[maxm],b[maxm],p;
inline void msort(int l,int r){
if(l==r) return;
int mid=(l+r)>>1;
msort(l,mid);
msort(mid+1,r);
int i=l,j=mid+1,k=i;
while(i<=mid&&j<=r){
if(a[i]>a[j]){
b[k++]=a[i++];
}
else{
b[k++]=a[j++];
ans+=mid-i+1;
}
}
while(i<=mid){
b[k++]=a[i++];
}
while(j<=r){
b[k++]=a[j++];
}
for(i=l;i<=r;i++){
a[i]=b[i];
}
}
int main(){
for(int i=1;i<=n;i++){
}
for(int i=1;i<=n;i++){
a[i]+=a[i-1]-p;
}
msort(0,n);
printf("%lldn",ans);
return 0;
}
``````

# (T3 text{Chess})

## 代码

``````int n,m,q;
map<int,int> numx,numy,cntx,cnty;
map<pii,int> mp;
ll ans;
inline void update(int x,int y,int w){
int tmp;
tmp=numx[x];
cntx[tmp]--;
ans=ans-(n-cnty[tmp]);
numx[x]^=w;
tmp=numx[x];
cntx[tmp]++;
ans=ans+(n-cnty[tmp]);
tmp=numy[y];
cnty[tmp]--;
ans=ans-(n-cntx[tmp]);
numy[y]^=w;
tmp=numy[y];
cnty[tmp]++;
ans=ans+(n-cntx[tmp]);
}
int main(){
cntx[0]=cnty[0]=n;
for(int i=1;i<=m;i++){
update(x,y,w);
mp[make_pair(x,y)]=w;
}
while(q--){
int tmp=mp[make_pair(x1,y1)];
update(x1,y1,tmp);
mp[make_pair(x2,y2)]=tmp;
update(x2,y2,tmp);
printf("%lldn",ans);
}
return 0;
}
``````

# (T4 text{Pref})

## 思路+代码1——哈希

``````int n;
char s[maxn];
ull power[maxn],h[maxn];
int dp[maxn];
map<ull,int> mp;
int ans,maxx;
int main(){
power[0]=1;
for(int i=1;i<=maxn;i++){
power[i]=power[i-1]*base1;
}
for(int i=1;i<=n;i++){
maxx=0;
scanf("%s",s+1);
int len=strlen(s+1);
ull preh=0,sufh=0;
for(int j=1;j<=len;j++){
preh=preh*base1+s[j];
sufh=sufh+s[len-j+1]*power[j-1];
if(preh==sufh){
maxx=max(maxx,mp[preh]);
}
}
mp[preh]=max(mp[preh],maxx+1);
ans=max(ans,maxx+1);
}
printf("%dn",ans);
return 0;
}
``````