szh_2003

1.0万

hhhhc
ybjt

asdqwe

goodLuck6
FengGeZhang

yunzhong99
tonngw
YOLO_0
sweet_

Briceby
glitters
anonymous233

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
using namespace std;
template<typename T,typename...Args>
void print(const T &x,const Args &...args)
{cout<<x;if constexpr(sizeof...(args))
{cout<<' ';print(args...);}else cout<<'\n';}
#define print(x,...) print(x,##__VA_ARGS__);
#define Print(a,l,r) rep(i,l,r)cout<<a[i]<<" \n"[i==r-1];
typedef long long LL;typedef pair<int,int> PII;
const int N=2e5+10;const int INF=0x3f3f3f3f;
int a[N];
int l[N],r[N];
bool st[N];
char s[N];
typedef pair<int,pair<int,int>> PIPII;
vector<PII> res;
int n;

void solve(){
cin>>n>>(s+1);
for(int i=1;i<=n;i++)cin>>a[i];

priority_queue<PIPII,vector<PIPII>,greater<PIPII>> heap;
for(int i=1;i<=n;i++){
l[i]=i-1;
r[i]=i+1;
if(i<n&&s[i]!=s[i+1]){
int t=abs(a[i]-a[i+1]);
heap.push({t,{i,i+1}});
// print(t,i,i+1)
}
}
while(heap.size()&&r[0]!=n+1){
auto t=heap.top();
auto [x,y]=t.second;
heap.pop();
if(st[x]||st[y])continue;
st[x]=st[y]=true;
res.push_back({x,y});
if(l[x]>=1&&r[y]<=n&&s[l[x]]!=s[r[y]]){
int q=abs(a[l[x]]-a[r[y]]);
heap.push({q,{l[x],r[y]}});
}
r[l[x]]=r[y];
l[r[y]]=l[x];
}
print(res.size())
for(auto &[x,y]:res){
print(x,y)
}
}

int main(){
cin.tie(0)->sync_with_stdio(0);
int T=1;
// cin>>T;
while(T--)solve();
return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
using namespace std;
template<typename T,typename...Args>
void print(const T &x,const Args &...args)
{cout<<x;if constexpr(sizeof...(args))
{cout<<' ';print(args...);}else cout<<'\n';}
#define print(x,...) print(x,##__VA_ARGS__);
#define Print(a,l,r) rep(i,l,r)cout<<a[i]<<" \n"[i==r-1];
typedef long long LL;typedef pair<int,int> PII;
const int N=20;const int INF=0x3f3f3f3f;
int dist[N][N];
int n;

void solve(){
cin>>n;
rep(i,0,n)
rep(j,0,n)
cin>>dist[i][j];
rep(k,0,n)
rep(i,0,n)
rep(j,0,n){
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
}
int res=0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
res=max(res,dist[i][j]);
print(res)
}

int main(){
cin.tie(0)->sync_with_stdio(0);
int T=1;
// cin>>T;
while(T--)solve();
return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
using namespace std;
template<typename T,typename...Args>
void print(const T &x,const Args &...args)
{cout<<x;if constexpr(sizeof...(args))
{cout<<' ';print(args...);}else cout<<'\n';}
#define print(x,...) print(x,##__VA_ARGS__);
#define Print(a,l,r) rep(i,l,r)cout<<a[i]<<" \n"[i==r-1];
typedef long long LL;typedef pair<int,int> PII;
const int N=2e5+10;const int INF=0x3f3f3f3f;
int n,m;
string s;

void solve(){
cin>>n>>m;
cin>>s;
while(m--){
int l,r;
char c1,c2;
cin>>l>>r>>c1>>c2;
l--,r--;
rep(i,l,r+1){
if(s[i]==c1)s[i]=c2;
}
}
print(s)

}

int main(){
cin.tie(0)->sync_with_stdio(0);
int T=1;
// cin>>T;
while(T--)solve();
return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
using namespace std;
template<typename T,typename...Args>
void print(const T &x,const Args &...args)
{cout<<x;if constexpr(sizeof...(args))
{cout<<' ';print(args...);}else cout<<'\n';}
#define print(x,...) print(x,##__VA_ARGS__);
#define Print(a,l,r) rep(i,l,r)cout<<a[i]<<" \n"[i==r-1];
typedef long long LL;typedef pair<int,int> PII;
const int N=5010;const int INF=0x3f3f3f3f;
int a[N];
int cnt[N];
int res[N];
int n;

void solve(){
cin>>n;
rep(i,0,n)cin>>a[i];
for(int i=0;i<n;i++){
// cnt.clear();
memset(cnt,0,sizeof cnt);
int ans=a[i];
for(int j=i;j<n;j++){
cnt[a[j]]++;
if(cnt[a[j]]>cnt[ans]){
ans=a[j];
}else if(cnt[a[j]]==cnt[ans]&&a[j]<ans){
ans=a[j];
}
res[ans]++;
}
}
Print(res,1,n+1)

}

int main(){
cin.tie(0)->sync_with_stdio(0);
int T=1;
// cin>>T;
while(T--)solve();
return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
using namespace std;
template<typename T,typename...Args>
void print(const T &x,const Args &...args)
{cout<<x;if constexpr(sizeof...(args))
{cout<<' ';print(args...);}else cout<<'\n';}
#define print(x,...) print(x,##__VA_ARGS__);
#define Print(a,l,r) rep(i,l,r)cout<<a[i]<<" \n"[i==r-1];
typedef long long LL;typedef pair<int,int> PII;
const int N=2e5+10;const int INF=0x3f3f3f3f;
int n;
int a[N];

void solve(){
cin>>n;
rep(i,0,n){
cin>>a[i];
}
int res=0;
for(int i=1;i<n-1;i++){
if(a[i]>a[i-1]&&a[i]>a[i+1])res++;
else if(a[i]<a[i-1]&&a[i]<a[i+1])res++;
}
print(res)
}

int main(){
cin.tie(0)->sync_with_stdio(0);
int T=1;
// cin>>T;
while(T--)solve();
return 0;
}


szh_2003
26天前
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
using namespace std;
template<typename T,typename...Args>
void print(const T &x,const Args &...args)
{cout<<x;if constexpr(sizeof...(args))
{cout<<' ';print(args...);}else cout<<'\n';}
#define print(x,...) print(x,##__VA_ARGS__);
#define Print(a,l,r) rep(i,l,r)cout<<a[i]<<" \n"[i==r-1];
typedef long long LL;typedef pair<int,int> PII;
const int N=2e5+10;const int INF=0x3f3f3f3f;

int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
struct Date{
int y,m,d;
}date[3];

bool isleap(int y){
return y%4==0&&y%100||y%400==0;
}

void solve(){
string a,b;
while(cin>>a>>b){
if(a>b)swap(a,b);
sscanf(a.c_str(),"%04d%02d%02d",&date[0].y,&date[0].m,&date[0].d);
sscanf(b.c_str(),"%04d%02d%02d",&date[1].y,&date[1].m,&date[1].d);
int s1=0,s2=0;
for(int i=0;i<date[0].y;i++){
s1+=365+isleap(i);
}
for(int i=0;i<date[1].y;i++){
s2+=365+isleap(i);
}
for(int i=1;i<date[0].m;i++){
s1+=month[i]+(i==2&&isleap(date[0].y));
}
for(int i=1;i<date[1].m;i++){
s2+=month[i]+(i==2&&isleap(date[1].y));
}
s1+=date[0].d;
s2+=date[1].d;
int res=s2-s1+1;
print(res)
}
}

int main(){
// cin.tie(0)->sync_with_stdio(0);
int T=1;
// cin>>T;
while(T--)solve();
return 0;
}


szh_2003
28天前
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
using namespace std;
template<typename T,typename...Args>
void print(const T &x,const Args &...args)
{cout<<x;if constexpr(sizeof...(args))
{cout<<' ';print(args...);}else cout<<'\n';}
#define print(x,...) print(x,##__VA_ARGS__);
#define Print(a,l,r) rep(i,l,r)cout<<a[i]<<" \n"[i==r-1];
typedef long long LL;typedef pair<int,int> PII;
const int N=1e6+10;const int INF=0x3f3f3f3f;
int primes[N],cnt;
bool st[N];

void get_primes(int n){
for(int i=2;i<=n;i++){
if(!st[i])primes[cnt++]=i;
for(int j=0;primes[j]*i<=n;j++){
st[primes[j]*i]=true;
if(i%primes[j]==0)break;
}
}
}

void solve(){
get_primes(1e6);
int k;
while(cin>>k){
print(primes[k-1])
}

}

int main(){
cin.tie(0)->sync_with_stdio(0);
int T=1;
// cin>>T;
while(T--)solve();
return 0;
}


szh_2003
28天前
a = int(input())
b = int(input())
print(a + b)
print(a - b)
print(a * b)


szh_2003
1个月前
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
using namespace std;
template<typename T,typename...Args>
void print(const T &x,const Args &...args)
{cout<<x;if constexpr(sizeof...(args))
{cout<<' ';print(args...);}else cout<<'\n';}
#define print(x,...) print(x,##__VA_ARGS__);
#define Print(a,l,r) rep(i,l,r)cout<<a[i]<<" \n"[i==r-1];
typedef long long LL;typedef pair<int,int> PII;
const int N=1e5+10;const int INF=0x3f3f3f3f;
int a[N],cnt[N];
int n;

void solve(){
int n;
cin>>n;
rep(i,0,n)cin>>a[i];
int res=0;
for(int i=0,j=0,s=0;i<n;i++){
if(!cnt[a[i]])s++;
cnt[a[i]]++;
while(s>2){
cnt[a[j]]--;
if(cnt[a[j]]==0)s--;
j++;
}
res=max(res,i-j+1);
}
print(res)
}

int main(){
cin.tie(0)->sync_with_stdio(0);
int T=1;
// cin>>T;
while(T--)solve();
return 0;
}


szh_2003
1个月前
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
using namespace std;
template<typename T,typename...Args>
void print(const T &x,const Args &...args)
{cout<<x;if constexpr(sizeof...(args))
{cout<<' ';print(args...);}else cout<<'\n';}
#define print(x,...) print(x,##__VA_ARGS__);
#define Print(a,l,r) rep(i,l,r)cout<<a[i]<<" \n"[i==r-1];
typedef long long LL;typedef pair<int,int> PII;
const int N=2e5+10;const int INF=0x3f3f3f3f;
map<string,int>mp;

void solve(){
int n;
cin>>n;
rep(i,0,n){
string s;
cin>>s;
mp[s]=i;
}
vector<pair<int,string>>v;
for(auto&[s,cnt]:mp){
pair<int,string> t={cnt,s};
v.pb(t);
}
sort(all(v),greater<pair<int,string>>());
for(auto&[cnt,s]:v){
print(s)
}
}

int main(){
cin.tie(0)->sync_with_stdio(0);
int T=1;
// cin>>T;
while(T--)solve();
return 0;
}