(本部2定格)教育Codeforcesラウンド78题解

シャッフルハッシュ

\ [制限時間:2秒\
クワッドメモリ制限:256メガバイト\] 処理\(S_1 \)各文字が現れる頻度、次にダブルポインタメンテナンス\(S_2 \)の長さ当たりの\(LEN(S_1)を\)文字の文字列の数、一定期間がある場合、表示され、\(S_1 \)文字の数が同じ、それが答えです。


見る

#include <map>
#include <set>
#include <list>
#include <tuple>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  fi         first
#define  se         second
#define  pb         push_back
#define  pii        pair<int, int>
#define  INOPEN     freopen("in.txt", "r", stdin)
#define  OUTOPEN    freopen("out.txt", "w", stdout)

typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 1e2 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

int n, m, k;
int cas, tol, T;

int cnt[26];
char s1[maxn], s2[maxn];

bool ok() {
    for(int i=0; i<26; i++) if(cnt[i])  return 0;
    return 1;
}

int main() {
    scanf("%d", &T);
    while(T--) {
        mes(cnt, 0);
        scanf("%s%s", s1+1, s2+1);
        n = strlen(s1+1), m = strlen(s2+1);
        if(n>m) {
            puts("NO");
            continue;
        }
        for(int i=1; i<=n; i++) cnt[s1[i]-'a']++;
        for(int i=1; i<=n; i++) cnt[s2[i]-'a']--;
        bool f = 0;
        for(int i=n; i<=m; i++) {
            if(ok())    f = 1;
            if(i==m)    break;
            cnt[s2[i+1]-'a']--;
            cnt[s2[i-n+1]-'a']++;
        }
        puts(f ? "YES" : "NO");
    }
    return 0;
}

AとB

\ [制限時間:1秒\
クワッドメモリ制限:256メガバイト\] あなたがそれを信じていないかもしれないと言う、強制\(oeis \)の前に。


見る

#include <map>
#include <set>
#include <list>
#include <tuple>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  fi         first
#define  se         second
#define  pb         push_back
#define  pii        pair<int, int>
#define  INOPEN     freopen("in.txt", "r", stdin)
#define  OUTOPEN    freopen("out.txt", "w", stdout)

typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 1e5 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

ll n, m;
int cas, tol, T;

int main() {
    scanf("%d", &T);
    while(T--) {
        ll a, b;
        scanf("%lld%lld", &a, &b);
        n = abs(a-b);
        ll k=0;
        for(; ; k++) {
            if(k*(k+1)/2 <= n && n<(k+1)*(k+2)/2)   break;
        }
        ll tk = k*(k+1)/2;
        ll ans;
        if(n == tk) ans = k;
        else {
            if(k%2 == 1) {
                if((n-tk)%2==1) ans = k+2;
                else    ans = k+1;
            } else {
                if((n-tk)%2==1) ans = k+1;
                else    ans = k+3;
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

ベリージャム

\ [制限時間:2秒\
クワッドメモリ制限:256メガバイト\] 前処理後半\(1 \)より(\ 2)\食べる(\ X)\ボトルに必要なステップの最小数、およびその後片食べるの前半のために\(I \)ボトルで(1 \)\よりも、必要に応じて(\ 2)\食べる(Y \)\ボトル、その後、後半に前処理を答えます。


見る

#include <map>
#include <set>
#include <list>
#include <tuple>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  fi         first
#define  se         second
#define  pb         push_back
#define  pii        pair<int, int>
#define  INOPEN     freopen("in.txt", "r", stdin)
#define  OUTOPEN    freopen("out.txt", "w", stdout)

typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 2e5 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

int n, m;
int cas, tol, T;

int a[maxn];
unordered_map<int, int> mp;

int main() {
    scanf("%d", &T);
    while(T--) {
        mp.clear();
        scanf("%d", &n);
        int y = 0;
        for(int i=1; i<=n+n; i++) {
            scanf("%d", &a[i]);
            y += a[i]==1 ? 1:-1;
        }
        if(y == 0) {
            printf("0\n");
            continue;
        }
        mp[0] = 0;
        for(int i=n+1, x=0; i<=n+n; i++) {
            x += a[i]==1 ? 1:-1;
            if(!mp.count(x))    mp[x] = i-n;
        }
//      for(auto t : mp)    printf("%d %d\n", t.fi, t.se);
        int ans = inf;
        for(int i=n; i>=0; i--) {
            if(mp.count(y)) 
                ans = min(ans, n-i+mp[y]);
            if(!i)  break;
            y -= a[i]==1 ? 1:-1;
        }
        printf("%d\n", ans);
    }
    return 0;
}

セグメントツリー

\ [制限時間:2秒\
クワッドメモリ制限:256メガバイト\】 プレスライン(L \)\押圧(R&LT \)\ソーティングとの列挙\(I \)線分、それを決定することができますラインさえのどちら側。

それはの列挙に見出すことができる\(I \)ときの線分、第\(I-1 \)線分\(L \)必ずしもIより(\ L)\ Iは実際にあったので、小見つける必要の前に\(I-1 \)の線分を、すべての真見つける\(P [i]が.L \当量のp [j]は.R \当量のp [i]を.R \) すべて\(J \を)

我々が維持できるように、このセクションでは、連続した部分である\(SET \)\(ペア\) 事前格納する(I-1 \)\エッジの\(R&LT \)位置及び数。その後、\(セット\)半分にすぐにすべてを見つけるために\(Jを\)

あなたはそれだけで追加することを意味し、ツリーを形成するようにしたいので、と\(N-1 \)エッジ、そして全体的な複雑さはあまりできません。


見る

#include <map>
#include <set>
#include <list>
#include <tuple>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  l          first
#define  r          second
#define  pb         push_back
#define  pii        pair<int, int>
#define  INOPEN     freopen("in.txt", "r", stdin)
#define  OUTOPEN    freopen("out.txt", "w", stdout)
 
typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 5e5 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

int n, m;
int cas, tol, T;

int fa[maxn];
pii p[maxn];
set<pii> st;

int find(int x) {
    return fa[x]==x ? x : fa[x]=find(fa[x]);
}

bool bind(int x, int y) {
    x = find(x), y = find(y);
    if(x == y)  return 0;
    fa[x] = y;
    return 1;
}

int main() {
    scanf("%d", &n);
    for(int i=1; i<=n; i++) {
        scanf("%d%d", &p[i].l, &p[i].r);
        fa[i] = i;
    }
    sort(p+1, p+1+n);
    st.clear();
    int sz = 0, f = 1;
    for(int i=1; i<=n; i++) {
        auto pos = st.lower_bound({p[i].l, -1});
        for(auto j = pos; j!=st.end(); j++) {
            if((*j).l > p[i].r) break;
            sz++;
            if(sz==n || !bind(i, (*j).r)) {
                f = 0;
                break;
            }
        }
        if(!f)  break;
        st.insert({p[i].r, i});
    }
    set<int> ans;
    for(int i=1; i<=n; i++) ans.insert(find(i));
    puts(ans.size()==1&&f ? "YES" : "NO");
    return 0;
}

問題のテストD

\ [制限時間:2秒\
クワッドメモリ制限:256メガバイト\] サンプルは、それが最初の配置ルールが何であるかを最初のシミュレーションを考える\(1 \)全体ツリーのルートとして、それが最初に決定することができる\ (P- [1] .R N-2 * = \)私がする必要があるので、それは、2つの直接人の息子を持っている\(R \) 2つの空の二人の息子を残す前に置く\(Rは\)今で、新しいクロスの出現を防ぐために、私は私自身には直接の息子入れなかった\(Lを\)以下の息子のためには、同じ理由で、再帰的に処理することができます。

その後の子である\(L \)ため、問題(1 \)\それぞれの息子が、これらはアップ一致しなければならないことを意味断面を持つことができないので、最終的に開始\(R \) 対応する\(L \)早く私の息子の背中を置くので、後でに行くべき、可能な限り小さくする必要があります\(DFS \)その決定するために、\(リットルを\)

使用される重複数を防止するために、とすることができる\(SET \)番号を使用することができる維持します。


見る

#include <map>
#include <set>
#include <list>
#include <tuple>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define  lowbit(x)  x & (-x)
#define  mes(a, b)  memset(a, b, sizeof a)
#define  l          first
#define  r          second
#define  pb         push_back
#define  pii        pair<int, int>
#define  INOPEN     freopen("in.txt", "r", stdin)
#define  OUTOPEN    freopen("out.txt", "w", stdout)
 
typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 5e5 + 10;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;

int n, m;
int cas, tol, T;

set<int> st;
pii p[maxn];
vector<int> g[maxn];

void dfs(int u, int fa) {
    int len = g[u].size();
    for(int i=0; i<len; i++) if(g[u][i] != fa) {
        p[g[u][i]].r = *(--st.end());
        st.erase((--st.end()));
    }
    p[u].l = *(--st.end());
    st.erase((--st.end()));
//  printf("p%d .l = %d .r = %d\n", u, p[u].l, p[u].r);
    for(int i=len-1; ~i; i--) if(g[u][i] != fa) {
        dfs(g[u][i], u);
    }
}

int main() {
    scanf("%d", &n);
    for(int i=2, u, v; i<=n; i++) {
        scanf("%d%d", &u, &v);
        g[u].pb(v), g[v].pb(u);
    }
    p[1].r = 2*n;
    for(int i=1; i<2*n; i++)    st.insert(i);
    dfs(1, 1);
    for(int i=1; i<=n; i++) printf("%d %d\n", p[i].l, p[i].r);
    return 0;
}
/*
3
1 2
1 3
*/

カード

\ [制限時間:4秒\クワッドメモリ制限:256メガバイト\]
留坑

おすすめ

転載: www.cnblogs.com/Jiaaaaaaaqi/p/12075688.html