https://codeforces.com/contest/1722/problem/A
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
cin>>T;
while(T--)
{
int n;
cin>>n;
string s;
cin>>s;
map<char,int> mp;
for(int i=0;i<s.size();i++)
mp[s[i]]++;
if(s.size()==5&&mp['T']==1&&mp['i']==1&&mp['m']==1&&mp['u']==1&&mp['r']==1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
https://codeforces.com/contest/1722/problem/B
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int a[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
cin>>T;
while(T--)
{
int n;
cin>>n;
string s;
cin>>s;
string c;
cin>>c;
bool flag=true;
for(int i=0;i<n;i++)
{
if(s[i]=='R'&&c[i]!='R')
{
flag=false;
break;
}
if(c[i]=='R'&&s[i]!='R')
{
flag=false;
break;
}
}
if(flag==false) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
s.clear();
c.clear();
}
return 0;
}
https://codeforces.com/contest/1722/problem/C
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int a[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
cin>>T;
while(T--)
{
int n;
cin>>n;
map<string,PII> mp;
int s1=0,s2=0,s3=0;
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
mp[s].first=1,mp[s].second=1;
s1+=3;
}
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
if(mp[s].first!=1)//没出现过
{
mp[s].first=2,mp[s].second=2;
s2+=3;
}
else
{
mp[s].second=2;
s1-=2;
s2+=1;
}
}
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
if(mp[s].first==1&&mp[s].second==2)
{
s1-=1;
s2-=1;
}
else if(mp[s].first==1&&mp[s].second==1)
{
s1-=2;
s3+=1;
}
else if(mp[s].first==2&&mp[s].second==2)
{
s2-=2;
s3+=1;
}
else s3+=3;
}
cout<<s1<<" "<<s2<<" "<<s3<<endl;
mp.clear();
}
return 0;
}
https://codeforces.com/contest/1722/problem/D
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int a[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
cin>>T;
while(T--)
{
LL n;
cin>>n;
string s;
cin>>s;
s=" "+s;
vector<LL> v;
LL sum=0;
for(LL i=1;i<=n;i++)
{
if(s[i]=='L')
{
LL l=i-1,r=n-i;
sum+=l;
if(l<r) v.push_back(r-l);
}
else
{
LL l=i-1,r=n-i;
sum+=r;
if(l>r) v.push_back(l-r);
}
}
if(v.size()==0)
{
for(LL i=1;i<=n;i++)
cout<<sum<<" ";
}
else
{
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
for(LL i=0;i<v.size();i++)
{
if(i==0) v[i]+=sum;
else v[i]+=v[i-1];
cout<<v[i]<<" ";
}
for(LL i=v.size()+1;i<=n;i++)
cout<<v[v.size()-1]<<" ";
}
cout<<endl;
}
return 0;
}
二位前缀和
https://codeforces.com/contest/1722/problem/E
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
LL a[M][M],s[M][M];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
cin>>T;
while(T--)
{
LL n,q;
cin>>n>>q;
memset(a,0,sizeof a);
memset(s,0,sizeof s);
for(int i=1;i<=n;i++)
{
LL x,y;
cin>>x>>y;
a[x][y]+=x*y;//面积叠加
}
//二维前缀和模板
for(int i=1;i<=1000;i++)
for(int j=1;j<=1000;j++)
s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
while(q--)
{
LL h1,w1,h2,w2;
cin>>h1>>w1>>h2>>w2;
//二维前缀和
//注意不能挨着最大的外框,所以要在(h2-1,w2-1)
cout<<s[h2-1][w2-1]-s[h1][w2-1]-s[h2-1][w1]+s[h1][w1]<<endl;
}
}
return 0;
}
https://codeforces.com/contest/1722/problem/F
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
char a[M][M];
bool vis[M][M];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
cin>>T;
while(T--)
{
LL n,m;
cin>>n>>m;
memset(a,'.',sizeof a);
memset(vis,false,sizeof vis);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
bool flag=true;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]=='*'&&vis[i][j]==false)
{
if(a[i][j+1]=='*'&&a[i+1][j]=='*')
{
if(a[i-1][j-1]=='*'||a[i-1][j]=='*'||a[i-1][j+1]=='*'||a[i-1][j+2]=='*') flag=false;
if(a[i][j-1]=='*'||a[i][j+2]=='*') flag=false;
if(a[i+1][j-1]=='*'||a[i+1][j+1]=='*'||a[i+1][j+2]=='*') flag=false;
if(a[i+2][j-1]=='*'||a[i+2][j]=='*'||a[i+2][j+1]=='*') flag=false;
if(flag!=false)
{
vis[i][j]=true; vis[i][j+1]=true; vis[i+1][j]=true;
}
//else cout<<"if 111"<<endl;
}
else if(a[i][j+1]=='*'&&a[i+1][j+1]=='*')
{
if(a[i-1][j-1]=='*'||a[i-1][j]=='*'||a[i-1][j+1]=='*'||a[i-1][j+2]=='*') flag=false;
if(a[i][j-1]=='*'||a[i][j+2]=='*') flag=false;
if(a[i+1][j-1]=='*'||a[i+1][j]=='*'||a[i+1][j+2]=='*') flag=false;
if(a[i+2][j]=='*'||a[i+2][j+1]=='*'||a[i+2][j+2]=='*') flag=false;
if(flag!=false)
{
vis[i][j]=true; vis[i][j+1]=true; vis[i+1][j+1]=true;
}
//else cout<<"else if 222"<<endl;
}
else if(a[i+1][j]=='*'&&a[i+1][j+1]=='*')
{
if(a[i-1][j-1]=='*'||a[i-1][j]=='*'||a[i-1][j+1]=='*') flag=false;
if(a[i][j-1]=='*'||a[i][j+1]=='*'||a[i][j+2]=='*') flag=false;
if(a[i+1][j-1]=='*'||a[i+1][j+2]=='*') flag=false;
if(a[i+2][j]=='*'||a[i+2][j+1]=='*'||a[i+2][j+2]=='*') flag=false;
if(flag!=false)
{
vis[i][j]=true; vis[i+1][j]=true; vis[i+1][j+1]=true;
}
//else cout<<"else if 333"<<endl;
}
else if(a[i+1][j-1]=='*'&&a[i+1][j]=='*')
{
if(a[i-1][j-1]=='*'||a[i-1][j]=='*'||a[i-1][j+1]=='*') flag=false;
if(a[i][j-2]=='*'||a[i][j-1]=='*'||a[i][j+1]=='*') flag=false;
if(a[i+1][j-2]=='*'||a[i+1][j+1]=='*') flag=false;
if(a[i+2][j-2]=='*'||a[i+2][j-1]=='*'||a[i+2][j]=='*'||a[i+2][j+1]=='*') flag=false;
if(flag!=false)
{
vis[i][j]=true; vis[i+1][j-1]=true; vis[i+1][j]=true;
}
//else cout<<"else if 444"<<endl;
}
else
{
flag=false;
//if(flag==false) cout<<i<<" "<<j<<"else if 555"<<endl;
}
}
}
if(flag==false) break;
}
if(flag==false) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return 0;
}
位运算
https://codeforces.com/contest/1722/problem/G
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
LL a[M][M],s[M][M];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
cin>>T;
while(T--)
{
LL n;
cin>>n;
vector<LL> v(n+1,0);//长度为n+1,初始化为0的变长数组
v[1]=1,v[2]=2;
LL x=3;
//定义数据时,避免过小产生重复的
for(LL i=3;i<=n-1;i++)
{
v[i]=i*2;
x^=v[i];
}
v[n]=x;
for(LL i=1;i<=n;i++)
cout<<v[i]<<" ";
cout<<endl;
}
return 0;
}
标签:typedef,int,LL,cin,long,ABCDEFG,tie,Div,817
From: https://www.cnblogs.com/Vivian-0918/p/16643743.html