目录
A
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve()
{
int n;cin>>n;
string s;cin>>s;
int x=0,y=0;
rep(i,0,s.size()-1){
if(s[i]=='B') y=i;
}
fep(i,s.size()-1,0){
if(s[i]=='B') x=i;
}
cout<<y-x+1<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
B
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve()
{
int n;
cin>>n;
vector<int>a(n+1);
rep(i,1,n) cin>>a[i];
map<int,set<char>>kk;
for(char i='a';i<='z';++i){
kk[0].insert(i);
}
string ans;
rep(i,1,n){
int cnt=a[i];
char c=*kk[cnt].begin();
kk[cnt].erase(c);
kk[cnt+1].insert(c);
ans+=c;
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
C
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve()
{
int n,m,k;
cin>>n>>m>>k;
vector<int>a(n+1),b(m+1);
set<int>s1,s2;
rep(i,1,n){
cin>>a[i];
s1.insert(a[i]);
}
rep(i,1,m){
cin>>b[i];
s2.insert(b[i]);
}
if(s1.size()<k/2||s2.size()<k/2){
cout<<"No"<<endl;
return;
}
int cnta=0,cntb=0,cntss=0;
rep(i,1,k){
if(s1.count(i)&&s2.count(i)){
cntss++;
}else if(s1.count(i)&&!s2.count(i)){
cnta++;
}else if(!s1.count(i)&&s2.count(i)){
cntb++;
}else{
cout<<"No"<<endl;
return;
}
}
if(cnta<k/2){
cntss-=(k/2-cnta);
}
if(cntb<k/2){
cntss-=(k/2-cntb);
}
if(cntss<0){
cout<<"No"<<endl;
}else{
cout<<"Yes"<<endl;
}
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
D
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
//#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
const int N=1e6+10;
#include <iostream>
using namespace std;
void solve()
{
int n;cin>>n;
vector<int>a(n+1),lmin(n+1),lmax(n+1);
rep(i,1,n){
cin>>a[i];
lmin[i]=lmax[i]=0;
}
stack<int>stk;
rep(i,1,n){
while(stk.size()&&a[i]<=a[stk.top()]) stk.pop();
if(stk.size()){
lmin[i]=stk.top();
}
stk.push(i);
}
while(stk.size()) stk.pop();
rep(i,1,n){
while(stk.size()&&a[i]>=a[stk.top()]) stk.pop();
if(stk.size()){
lmax[i]=stk.top();
}
stk.push(i);
}
// rep(i,1,n) cout<<lmin[i]<<' ';
// cout<<endl;
// rep(i,1,n) cout<<lmax[i]<<' ';
// cout<<endl;
int q;cin>>q;
while(q--){
int l,r;cin>>l>>r;
int minn=lmin[r],maxx=lmax[r];
if(minn>=l){
cout<<minn<<' '<<r<<endl;
}else if(maxx>=l){
cout<<maxx<<' '<<r<<endl;
}else{
cout<<"-1 -1"<<endl;
}
}
cout<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
E
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
const int N=1e6+10;
#include <iostream>
using namespace std;
void solve()
{
int n,k;cin>>n>>k;
vector<int>ans(n+1);
int bb=1,dd=n;
rep(i,1,k){
if(i&1){
//从大到小去放
for(int j=i;j<=n;j+=k){
ans[j]=dd--;
}
}else{
//从小到大去放
for(int j=i;j<=n;j+=k){
ans[j]=bb++;
}
}
}
rep(i,1,ans.size()-1) cout<<ans[i]<<' ';
cout<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
F
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
const int N=2e5+10;
int fa[N];
struct edge{
int x,y,w;
}e[N];
vector<int>g[N];
int find(int x){
if(x==fa[x]) return x;
return fa[x]=find(fa[x]);
}
int n,m;
vector<int>path;
int vis[N];
void dfs(int u,int tag){
vis[u]=1;
path.pb(u);
if(u==tag){
cout<<path.size()<<endl;
for(auto i:path) cout<<i<<' ';
cout<<endl;
}else{
for(auto y:g[u]){
if(vis[y]) continue;
dfs(y,tag);
}
}
path.pop_back();
}
void solve()
{
cin>>n>>m;
rep(i,1,n) fa[i]=i;
rep(i,1,n) vis[i]=0;
path.clear();
rep(i,1,n) if(g[i].size()) g[i].clear();
rep(i,1,m){
int u,v,w;cin>>u>>v>>w;
e[i]={u,v,w};
}
sort(e+1,e+1+m,[&](edge t1,edge t2){return t1.w>t2.w;});
int id=0,ans=1e9;
rep(i,1,m){
int u=find(e[i].x),v=find(e[i].y);
if(u==v){
id=i;
ans=min(ans,e[i].w);
}else{
fa[u]=v;
}
}
cout<<ans<<' ';
rep(i,1,m){
if(id==i) continue;
int x=e[i].x,y=e[i].y;
g[x].pb(y);g[y].pb(x);
}
dfs(e[id].x,e[id].y);
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}
标签:int,rep,Codeforces,long,cin,pair,Div,923,define
From: https://www.cnblogs.com/cxy8/p/18010833