“21天好习惯”第一期-20 实战篇(1)

21天零基础入门ACM

21天零基础入门ACM之 第20天

2020江西省icpc

比赛链接:https://ac.nowcoder.com/acm/contest/8827

B 题:

在这里插入图片描述
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define sc(x) scanf("%d",&x)
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll qpow(ll a, ll b) { ll ans = 1;    while (b) { if (b & 1)    ans *= a;        b >>= 1;        a *= a; }    return ans; }    
ll qpow(ll a, ll b, ll mod) { ll ans = 1;  a%=mod; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; }
inline ll read() { ll s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();    return s * w; }

const int mod=1e9+7;
const int N=1e5+7;

int n,m;

void solve(){
    cin>>n>>m;
    ll ans=0;
    for(int i=1;i<=m;i++){
        ans+=i;
    }
    if(ans<=n) cout<<"possible"<<endl;
    else puts("impossible");
}

int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

E 题

在这里插入图片描述
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define sc(x) scanf("%d",&x)
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll qpow(ll a, ll b) { ll ans = 1;    while (b) { if (b & 1)    ans *= a;        b >>= 1;        a *= a; }    return ans; }    
ll qpow(ll a, ll b, ll mod) { ll ans = 1;  a%=mod; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; }
inline ll read() { ll s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();    return s * w; }

const int mod=1e9+7;
const int N=1e6+7;

ll nums[N],sum[N];
map<int,int> cnt;
int n;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>nums[i],nums[i]=nums[i-1]^(1<<nums[i]);
    ll ans=0;
    cnt[0]=1;
    for(int i=1;i<=n;i++) ans+=cnt[nums[i]],cnt[nums[i]]++;
    cout<<ans<<endl;
}

G题

在这里插入图片描述
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define sc(x) scanf("%d",&x)
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
inline ll read() { ll s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();    return s * w; }

const int mod=998244353;
const int N=1e5+7;

ll qpow(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1)
            ans *= a;
        b >>= 1;
        a *= a;
    }
    return ans;
}
ll qpow(ll a, ll b, ll mod) {
    ll ans = 1;
    a %= mod;
    while (b) {
        if (b & 1)
            (ans *= a) %= mod;
        b >>= 1;
        (a *= a) %= mod;
    }
    return ans % mod;
}

ll n,m;
int main(){
    cin>>n>>m;
    cout<<qpow(m+1,n,mod)<<endl;
}

H 题

在这里插入图片描述
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define sc(x) scanf("%d",&x)
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll qpow(ll a, ll b) { ll ans = 1;    while (b) { if (b & 1)    ans *= a;        b >>= 1;        a *= a; }    return ans; }    
ll qpow(ll a, ll b, ll mod) { ll ans = 1;  a%=mod; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; }
inline ll read() { ll s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();    return s * w; }
const int mod=1e9+7;
const int N=1e5+7;

int n,m;
int nums[N],tree[N*4];

void pushup(int k){
    tree[k]=min(tree[k<<1],tree[k<<1|1]);
}

void build(int k,int l,int r){
    if(l==r) {tree[k]=nums[l];return;}
    int mid=(l+r)>>1;
    build(k<<1, l, mid);
    build(k<<1|1,mid+1,r);
    pushup(k);
}

void updata(int pos,int val,int k,int l,int r){
    if(l==r) {
        nums[pos]=val;
        tree[k]=val;
        return;
    }
    int mid = (l+r)>>1;
    if(pos<=mid) updata(pos,val,k<<1,l,mid);
    else  updata(pos,val,k<<1|1,mid+1,r);
    pushup(k);
}

int query(int k,int l,int r,int L,int R){
    if(l>=L&&r<=R) return tree[k];
    int mid=(l+r)>>1;
    int ans=INT_MAX;
    if(L<=mid) ans=min(ans,query(k<<1,l,mid,L,R)); 
    if(R>mid) ans=min(ans,query(k<<1|1,mid+1,r,L,R));
    return ans;
}


int main(){
    while(cin>>n>>m){
        for(int i=1;i<=n;i++) cin>>nums[i];
        build(1,1,n);
        //for(int i=1;i<=50;i++) cout<<tree[i]<<" ";
        while(m--){
            int op,x,y;
            cin>>op;
            if(op==1){
                cin>>x>>y;
                updata(x,y,1,1,n);
            }
            else{
                cin>>x;
                int l,r,lans,rans;
                l=1,r=x;
                while(l<=r){
                    int mid=(l+r)>>1;
                    if(query(1,1,n,mid,x)>=nums[x]) r=mid-1;
                    else l=mid+1;
                }
                lans=l;
                l=x,r=n;
                while(l<=r){
                    int mid=(l+r)>>1;
                    if(query(1,1,n,x,mid)<nums[x]) r=mid-1;
                    else l=mid+1;
                }
                rans=r;
                cout<<1LL*(x-lans+1)*(rans-x+1)<<endl;
            }
        }
    }
}



I 题

在这里插入图片描述
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define sc(x) scanf("%d",&x)
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll qpow(ll a, ll b) { ll ans = 1;    while (b) { if (b & 1)    ans *= a;        b >>= 1;        a *= a; }    return ans; }    
ll qpow(ll a, ll b, ll mod) { ll ans = 1;  a%=mod; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; }
inline ll read() { ll s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();    return s * w; }

const int mod=1e9+7;
const int N=1e5+7;

ll k,n,m;

int main(){
    while(cin>>k>>n>>m){
        n++;m++;
        if(n+m<=k+1) cout<<(n+m-1)*(n+m-2)/2+n-1<<endl;
        else {
            n=k-n+1;
            m=k-m+1;
            cout<<k*k-(n+m-1) * (n+m-2)/2-n<<endl;
        }
    }
}

M 题

在这里插入图片描述
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;

const int mod=1e9+7;
const int N=1e5+7;

int main(){
    string s,s1;
    cin>>s>>s1;
    s+=s1;
    cout<<s<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值