Codeforces Round #632 (Div. 2) 总结

仍然按照惯例打半场,前 20 分钟签完 ABC,而后因 D 写 WA 懵逼到死

A

很容易想到只让第一个格子为 W 即可

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

signed main() {
    ios::sync_with_stdio(false);
    int t,n,m;
    cin>>t;
    while(t--) {
        cin>>n>>m;
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=m;j++) {
                if(i==1 && j==1) cout<<"W";
                else cout<<"B";
            }
            cout<<endl;
        }
    }
}

B

\(b[i]>a[i]\)\(a[1..i-1]\) 中必须有 \(1\),反之亦然

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

#define int long long
const int N = 1000005;
int t,n,a[N],b[N];

signed main() {
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--) {
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        for(int i=1;i<=n;i++) cin>>b[i];
        int ng=0,ps=0,fg=1;
        for(int i=1;i<=n;i++) {
            if(b[i]>a[i] && ps==0) fg=0;
            if(b[i]<a[i] && ng==0) fg=0;
            if(a[i]==-1) ng=1;
            if(a[i]==1) ps=1;
        }
        if(fg) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

C

转化为前缀和相等,然后尺取法即可

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

#define int long long
const int N = 1000005;

int n,a[N],s[N],ans=0;

set <int> st;

signed main() {
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) s[i]=s[i-1]+a[i];
    int pos=1;
    st.insert(0);
    for(int i=1;i<=n;i++) {
        while(pos<=n && st.find(s[pos])==st.end()) {
            st.insert(s[pos]);
            ++pos;
        }
        ans+=pos-i;
        if(st.find(s[i-1])!=st.end()) st.erase(s[i-1]);
    }
    cout<<ans;
}

D

WA掉了,待填坑

F

待填坑

猜你喜欢

转载自www.cnblogs.com/mollnn/p/12664323.html