T1:词典
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
char s[3005],mx[3005][3005],mn[3005][3005],pr[3005][3005],sf[3005][3005];int c[35];
signed main(){
int n=read(),m=read();
for(int i=1;i<=n;i++){
scanf("%s",s);int pmx=0,pmn=0;
for(int j=0;j<m;j++)c[s[j]-'a']++;
for(int j=25;j>=0;j--){
while(c[j])mx[i][pmx++]=j+'a',c[j]--;
}
for(int j=0;j<m;j++)c[s[j]-'a']++;
for(int j=0;j<=25;j++){
while(c[j])mn[i][pmn++]=j+'a',c[j]--;
}
}
for(int j=0;j<m;j++)pr[1][j]=mx[1][j];
for(int i=2;i<=n;i++){
int flag=0;
for(int j=0;j<m;j++){
if(pr[i-1][j]<mx[i][j]){
flag=0;break;
}
else if(pr[i-1][j]>mx[i][j]){
flag=1;break;
}
}
if(!flag){
for(int j=0;j<m;j++)pr[i][j]=pr[i-1][j];
}
else{
for(int j=0;j<m;j++)pr[i][j]=mx[i][j];
}
}
for(int j=0;j<m;j++)sf[n][j]=mx[n][j];
for(int i=n-1;i>=1;i--){
int flag=0;
for(int j=0;j<m;j++){
if(sf[i+1][j]<mx[i][j]){
flag=0;break;
}
else if(sf[i+1][j]>mx[i][j]){
flag=1;break;
}
}
if(!flag){
for(int j=0;j<m;j++)sf[i][j]=sf[i+1][j];
}
else{
for(int j=0;j<m;j++)sf[i][j]=mx[i][j];
}
}
for(int i=1;i<=n;i++){
int flag=1;
if(i>1){
int tag=0;
for(int j=0;j<m;j++){
if(mn[i][j]>pr[i-1][j]){
tag=0;break;
}
else if(mn[i][j]<pr[i-1][j]){
tag=1;break;
}
}
flag&=tag;
}
if(i<n){
int tag=0;
for(int j=0;j<m;j++){
if(mn[i][j]>sf[i+1][j]){
tag=0;break;
}
else if(mn[i][j]<sf[i+1][j]){
tag=1;break;
}
}
flag&=tag;
}
if(flag)putchar('1');
else putchar('0');
}
return 0;
}
T2:三值逻辑
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e18;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
int C,T,a[200005],b[200005],fa[200005];char op[10];
int find(int x){
return ((x==fa[x])?x:fa[x]=find(fa[x]));
}
void merge(int x,int y){
if((x=find(x))==(y=find(y)))return;
fa[x]=y;
}
void solve(){
int n=read(),m=read();
for(int i=1;i<=n;i++)a[i]=1,b[i]=i,a[i+n]=-1,b[i+n]=i;
for(int i=1;i<=m;i++){
scanf("%s",op);
if(op[0]=='+'){
int x=read(),y=read();
a[x]=a[y],b[x]=b[y];
}
else if(op[0]=='-'){
int x=read(),y=read();
a[x]=-a[y],b[x]=b[y];
}
else{
int x=read();
if(op[0]=='T')a[x]=0,b[x]=-1;
else if(op[0]=='F')a[x]=0,b[x]=-2;
else a[x]=0,b[x]=-3;
}
}
for(int i=1;i<=n+n;i++)fa[i]=i;
for(int i=1;i<=n;i++){
if(a[i]==0){
a[find(i)]=a[i],b[find(i)]=b[i];
if(b[i]!=-3)a[find(i+n)]=a[i],b[find(i+n)]=-3-b[i];
else a[find(i+n)]=a[i],b[find(i+n)]=b[i];
}
else if(a[i]==1){
if(find(i)==find(b[i]+n)){
merge(i,b[i]);merge(i+n,b[i]);
a[find(i)]=0,b[find(i)]=-3;
}
else merge(i,b[i]),merge(i+n,b[i]+n);
}
else{
if(find(i)==find(b[i])){
merge(i,b[i]+n);merge(i+n,b[i]+n);
a[find(i)]=0,b[find(i)]=-3;
}
else merge(i,b[i]+n),merge(i+n,b[i]);
}
}
int ans=0;
for(int i=1;i<=n;i++){
if(a[find(i)]==0&&b[find(i)]==-3)ans++;
}
printf("%lld\n",ans);
}
signed main(){
C=read(),T=read();
while(T--){
solve();
}
return 0;
}
T3:双序列拓展
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 5e5 + 10;
int n, m, q, x[N], y[N], tx[N], ty[N];
bool flag;
struct Node {
int pre, suf;
void operator=(const int &x) {pre = suf = x;}
} X[N], Y[N];
bool check(const int x[], const int y[]) {
if (x[1] == y[1]) return 0;
else if (x[1] > y[1]) swap(x, y), swap(n, m), flag = 1;
int mx = x[1]; X[1] = x[1], X[n] = x[n];
for (int i = 2; i <= n; i++) mx = max(mx, x[i]), X[i].pre = min(X[i - 1].pre, x[i]);
for (int i = n - 1; i; i--) X[i].suf = min(X[i + 1].suf, x[i]);
int mn = y[1]; Y[1] = y[1], Y[m] = y[m];
for (int i = 2; i <= m; i++) mn = min(mn, y[i]), Y[i].pre = max(Y[i - 1].pre, y[i]);
for (int i = m - 1; i; i--) Y[i].suf = max(Y[i + 1].suf, y[i]);
if (mx >= Y[1].suf || mn <= X[1].suf) return 0;
for (int i = 1, j = 1; i <= n; i++) {
while (j <= m && y[j] > X[i].pre) j++;
if (j == m + 1) break;
if (x[i] >= Y[j].pre) return 0;
}
for (int i = n, j = m; i; i--) {
while (j && y[j] > X[i].suf) j--;
if (!j) break;
if (x[i] >= Y[j].suf) return 0;
}
return 1;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> n >> m >> q;
for (int i = 1; i <= n; i++) cin >> x[i];
for (int i = 1; i <= m; i++) cin >> y[i];
cout << check(x, y);
while (q--) {
if (flag) swap(n, m), flag = 0;
memcpy(tx, x, sizeof(tx)), memcpy(ty, y, sizeof(ty));
int kx, ky, p, v; cin >> kx >> ky;
while (kx--) cin >> p >> v, tx[p] = v;
while (ky--) cin >> p >> v, ty[p] = v;
cout << check(tx, ty);
}
return 0;
}
T4:天天爱打卡(run)
注:本题绝对是毒瘤!
#include<bits/stdc++.h>
#define int long long
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int,int>pii;
const int inf=1e18;
inline int read(){
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
struct segtree{
#define ls p<<1
#define rs p<<1|1
#define lson l,mid,ls
#define rson mid+1,r,rs
struct Node{
int mx,tag;
}c[800005];
void pushup(int p){
c[p].mx=max(c[ls].mx,c[rs].mx);
}
void pushdown(int p){
if(!c[p].tag)return;
c[ls].tag+=c[p].tag,c[rs].tag+=c[p].tag;
c[ls].mx+=c[p].tag,c[rs].mx+=c[p].tag;
c[p].tag=0;
}
void build(int l,int r,int p){
c[p].tag=0;
if(l==r){
c[p].mx=0;
return;
}
int mid=(l+r)>>1;
build(lson);build(rson);
pushup(p);
}
void add(int l,int r,int p,int L,int R,int k){
if(L<=l&&r<=R){
c[p].mx+=k,c[p].tag+=k;
return;
}
int mid=(l+r)>>1;pushdown(p);
if(L<=mid)add(lson,L,R,k);
if(R>mid)add(rson,L,R,k);
pushup(p);
}
int ask(int l,int r,int p,int L,int R){
if(L>R)return -inf;
if(L<=l&&r<=R){
return c[p].mx;
}
int mid=(l+r)>>1,res=-inf;pushdown(p);
if(L<=mid)res=max(res,ask(lson,L,R));
if(R>mid)res=max(res,ask(rson,L,R));
return res;
}
#undef ls
#undef rs
#undef lson
#undef rson
}Tr;
int C,T,l[100005],r[100005],w[100005],b[200005],f[200005];vector<int>v[200005];
void solve(){
int n=read(),m=read(),k=read(),d=read(),tot=0;
for(int i=1,x,y;i<=m;i++){
x=read(),y=read(),l[i]=x-y+1,r[i]=x,w[i]=read();
b[++tot]=l[i]-1,b[++tot]=r[i]+1;
}
sort(b+1,b+tot+1);tot=unique(b+1,b+tot+1)-b-1;
for(int i=1;i<=m;i++){
l[i]=lower_bound(b+1,b+tot+1,l[i]-1)-b;
r[i]=lower_bound(b+1,b+tot+1,r[i]+1)-b;
v[r[i]].push_back(i);
}
Tr.build(1,tot,1);f[1]=0;Tr.add(1,tot,1,1,1,f[1]+b[1]*d);
for(int i=2,lim=1;i<=tot;i++){
for(auto x:v[i])Tr.add(1,tot,1,0,l[x],w[x]);
while(b[i]-b[lim]-1>k)lim++;
f[i]=max(f[i-1],Tr.ask(1,tot,1,lim,i-1)-(b[i]-1)*d);
Tr.add(1,tot,1,i,i,f[i]+b[i]*d);
}
printf("%lld\n",f[tot]);
for(int i=0;i<=tot;i++)v[i].clear(),f[i]=0;
}
signed main(){
C=read(),T=read();
while(T--){
solve();
}
return 0;
}
标签:ch,return,int,题解,提高,23NOIP,while,read,--
From: https://blog.csdn.net/HRC122449/article/details/139293790