Yet Another Broken Keyboard[双指针]
Posted waryan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Yet Another Broken Keyboard[双指针]相关的知识,希望对你有一定的参考价值。
题目大意:
求贡献,已知公式n*(n+1)/2,求总和
收获:
long long的转换技巧只能在乘或除上进行
#include<bits/stdc++.h> typedef long long ll; using namespace std; const int N=2e5+10; int main() { int n,k;cin>>n>>k; set<char>st;string s,s1; cin>>s; char tmp; for(int i=0;i<k;++i) cin>>tmp,st.insert(tmp); ll ans=0; for(int i=0;i<s.size();++i){ int j=i; while(j<s.size()&&st.count(s[j])) ++j; ans+=1ll*(j-i)*(j-i+1)/2; i=j; } cout<<ans<<endl; return 0; }
以上是关于Yet Another Broken Keyboard[双指针]的主要内容,如果未能解决你的问题,请参考以下文章
C - Yet Another Broken Keyboard
D. Yet Another Yet Another Task (ST表模版 + 单调队列)
CF-1359 D. Yet Another Yet Another Task ST表+单调队列
CF-1359 D. Yet Another Yet Another Task ST表+单调队列
Educational Codeforces Round 88 (Rated for Div. 2) D. Yet Another Yet Another Task
Educational Codeforces Round 88 (Rated for Div. 2) D. Yet Another Yet Another Task