#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#include <iomanip>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define seteps(N) setprecision(N)
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<char,char> PCC;
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef __int128 lll;
const int N=2*1010;
const int M=1e6+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const lll one=1;
ll f[N][N];
void solve(){
double p=3.1415926;
int n,m;
while(cin>>n>>m){
rep(i,0,n+m+1){
rep(j,0,n+m+1){
f[i][j]=0;
}
}
f[0][0]=1;
rep(i,0,n+m+1){
rep(j,0,n+m+1){
if(i>=1 && i-j<=n) f[i][j]=(f[i][j]+f[i-1][j])%mod;
if(j>=1 && j-i<=m) f[i][j]=(f[i][j]+f[i][j-1])%mod;
}
}
cout<<f[n+m][n+m]<<endl;
}
}
int main(){
IOS;
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
//int t;cin>>t;
//while(t--)
solve();
return 0;
}
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <set>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<char,char> PCC;
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef __int128 lll;
const int N=2*1e5+10;
const int M=1e6+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const lll one=1;
int a[N];
void solve(){
int n;
cin>>n;
rep(i,1,n+1) cin>>a[i];
ll ans=0;
map<int,int> used;
rep(i,1,n+1){
if(!used[a[i]]){
ans+=(i*(n-i+1));
}else{
ans+=(n-i+1)*(i-used[a[i]]);
}
used[a[i]]=i;
}
cout<<ans<<endl;
}
int main(){
IOS;
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
//int t;cin>>t;
//while(t--)
solve();
return 0;
}
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <set>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<char,char> PCC;
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef __int128 lll;
const int N=2*1e5+10;
const int M=1e6+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const lll one=1;
int a[N];
void solve(){
ll a,b,x,y;
while(cin>>x>>a>>y>>b){
lll res1=one*x*b;
lll res2=one*a*y;
if(res1==res2) cout<<"="<<endl;
else if(res1<res2) cout<<"<"<<endl;
else cout<<">"<<endl;
}
}
int main(){
IOS;
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
//int t;cin>>t;
//while(t--)
solve();
return 0;
}
使用一个字符串来储存删除过后的字符串序列,使用一个变量来表示删除后的字符串下标。每次符合条件时,变量都要向前移3位,模拟这个过程即可。
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define sz(x) x.size()
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<char,char> PCC;
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef __int128 lll;
const int N=2*1e5+10;
const int M=1e6+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const lll one=1;
void solve(){
string s,v;
cin>>s;
v=s;
int now=0,ans=0;
rep(i,0,sz(s)){
now++;
v[now]=s[i];
if(now>=3 && v[now]==v[now-1] && v[now-2]==v[now]){
ans++;
now-=3;
}
}
cout<<ans<<endl;
}
int main(){
IOS;
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
//int t;cin>>t;
//while(t--)
solve();
return 0;
}