Educational Codeforces Round 67

A.

加加减减即可。

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
const int maxn = 105000;
int main(){
    int n;
    ll x,y,z;
    cin>>n;
    for(int i = 1;i <= n;i++){
        cin>>x>>y>>z;
        cout<<max(x-y,x-z)+1<<endl;
    }
 
    return 0;
}
View Code

B.

把字母拆开算贡献

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define ll long long
using namespace std;
const int maxn = 205000;
int tb[30][maxn];
int pos[30],amt[30];
char s[maxn],t[maxn];
int main(){
    int n,m;
    cin>>n;
    scanf("%s",s+1);
    fo(i,1,n){
        int tmp = s[i]-'a';
        pos[tmp]++;
        tb[tmp][pos[tmp]] = i;
    }
    cin>>m;
    fo(i,1,m){
        scanf("%s",t+1);
        int l2 = strlen(t+1);
        memset(amt,0,sizeof(amt));
        fo(j,1,l2){
            amt[t[j]-'a']++;
        }
        int ans = 0;
        fo(j,0,26){
            ans = max(ans,tb[j][amt[j]]);
        }
        printf("%d\n",ans);
    }
    return 0;
}
View Code

C.

构造一个数组,一部分是非降序,一部分不是非降序

非降序的让它和前一个相等,否则-1

区间处理上容易出问题,因为不同区间的端点可能重合

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define ll long long
using namespace std;
const int maxn = 2050;
int n,m;
int sl[maxn],sr[maxn];
int nl[maxn],nr[maxn];
int lp[maxn],rp[maxn],tt[maxn];
int a[maxn];
vector<int> lst;
int main(){
    int n,m;
    cin>>n>>m;
    int t,l,r;
    fo(i,1,m) {
        scanf("%d%d%d", &t, &l, &r);
        tt[i] = t;
        if (t == 1) {
            sl[l]++;
            sr[r]++;
        } else {
            nl[l] = 1;
            nr[r] = 1;
        }
        lp[i] = l;
        rp[i] = r;
    }
    int ins=0,inn=0,ful=0,now=n+1;
    for(int i = 1;i <= n;i++){
        if(ins)a[i] = now;
        if(!ins)a[i] = --now;
        if(sl[i])ins+=sl[i];
        if(nl[i])inn++;
        if(sr[i])ins-=sr[i];
        if(nr[i])inn--;
    }
    for(int i = 1;i <= m;i++){
        if(tt[i]==1)continue;
        bool ok=false;
        fo(j,lp[i]+1,rp[i]){
            if(a[j]<a[j-1]){
                ok=true;
                break;
            }
        }
        if(ok)continue;
        else{
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES"<<endl;
    fo(i,1,n){
        printf("%d ",a[i]);
    }
    return 0;
}
View Code

 

posted @ 2019-07-02 02:55  ACforever  阅读(158)  评论(0编辑  收藏  举报