Codeforces Round #344 (Div. 2)

Source: Internet
Author: User

Water A-interview

Note is or is not an XOR or

#include <bits/stdc++.h>int a[1005], b[1005];int main ()  {    int n;  scanf ("%d", &n);    for (int i=0; i<n; ++i) {        scanf ("%d", a+i);    }    for (int i=0; i<n; ++i) {        scanf ("%d", b+i);    }    int ans = 0;    for (int i=0; i<n; ++i) {        int x = 0, y = 0;        for (int j=i; j<n; ++j) {            x |= a[j];  Y |= b[j];            Ans = Std::max (ans, x + y);        }    }    printf ("%d\n", ans);    return 0;}

Water B-print Check

COLOR[I][J] = max (Timei (ROWI), Timej (COLJ)))

#include <bits/stdc++.h>const int N = 5e3 + 5;int a[n][n];std::p air<int, int> Row[n], Col[n];int main () {    int n, m, K;    scanf ("%d%d%d", &n, &m, &k);    for (int op, x, Y, I=1; i<=k; ++i) {        scanf ("%d%d%d", &op, &x, &y);        if (op = = 1) {            row[x] = Std::make_pair (y, i);        } else {            col[x] = Std::make_pair (y, i);}    }    for (int i=1; i<=n; ++i) {        for (int j=1; j<=m; ++j) {            int tr = row[i].second, TC = Col[j].second;            if (tr > TC && TR > 0) {                a[i][j] = Row[i].first;            } else if (TC > TR && TC > 0) {
   A[I][J] = Col[j].first;}}    }    for (int i=1; i<=n; ++i) {        for (int j=1; j<=m; ++j) {            printf ("%d%c", a[i][j], j = = m? ' \ n ': ');        }    }    return 0;}

Monotone Queue + Sort C-report

Test instructions: For M operations, each operation makes [1, R] range of A[i] ascending or descending sort, ask A[i] final result

Analysis: Because the left endpoint is fixed, the right endpoint is far and the operation time can cover the previous right end close to the operation, so first from the right endpoint farthest and time after the time, and then similar as long as the right endpoint descending position, that is, maintaining a monotonous queue. The last operation in the queue is not longer than the previous length, and the number of the reduced length k is the number of the first K or the first k in the previous range.

#include <bits/stdc++.h>const int n = 2e5 + 5;int a[n], B[n];int r[n], T[n];int main () {    int N, m; scanf ("%d%d" , &n, &m);    for (int i=1; i<=n; ++i) {        scanf ("%d", a+i);    }    int s = 0;    for (int x, y, I=1; i<=m; ++i) {        scanf ("%d%d", &x, &y);        while (s > 0 && y >= r[s-1])    s--;        T[s] = x;   R[s] = y;   s++;    }    r[s++] = 0;    int bl = 1, br = r[0];    for (int i=bl; i<=br; ++i) b[i] = A[i];    Std::sort (b+1, B+1+BR);    for (int i=1, i<s; ++i) {for        (int j=r[i-1]; j>r[i];--j) {            a[j] = (t[i-1] = = 1)? b[br--]: b[bl++];
   
    }    }    for (int i=1; i<=n; ++i) {        printf ("%d", A[i]);    }    Puts ("");    return 0;}
   

KMP D-messenger

Test instructions: Give two strings and ask the number of occurrences of the latter in the former. Given in the way: 1-a 2-b 3-c 4-d (ABBCCCDDD)

Analysis: Actually want to understand that this is the simple KMP problem, the number of the first and last text string must be more than the pattern string, and the inside is exactly equal. Also consider special cases, compressed after m==1 or 2 o'clock.

#include <bits/stdc++.h>typedef long long ll;const int N = 2e5 + 5;struct part {ll len; char ch;    BOOL operator = = (const part &AMP;RHS) Const {return len = = Rhs.len && ch = = rhs.ch;    } BOOL operator >= (const part &AMP;RHS) Const {return len >= rhs.len && ch = = rhs.ch;    } bool Operator! = (const part &AMP;RHS) const {return len! = Rhs.len | | ch! = rhs.ch; }};    Part a[n], b[n];int fail[n];int compress (part *c, int N) {int m = 0;        for (int i=1; i<n; ++i) {if (c[m].ch = = c[i].ch) {C[m].len + = C[i].len;        } else {c[++m] = C[i]; }} return M + 1;}  void Get_fail (part *p, int lenp) {int i = 0, j =-1;    Fail[0] =-1; while (I < LENP) {if (j = =-1 | |   P[J] = = P[i]) {++i; ++j;        Fail[i] = j;        } else {j = fail[j];    }}}ll KMP (part *c, Int. N, part *d, int m) {get_fail (D, M);    int i = 0, j = 0;  ll ret = 0;  while (I < n) {while (J! =-1 && c[i]! = d[j]) j = fail[j];    i++;        j + +;            if (j = = m) {if (C[i] >= d[m] && c[i-m-1] >= d[-1]) ret++;        j = Fail[j]; }} return ret;}   int main () {int n, m;    scanf ("%d%d", &n, &m);    int bug = 0;    Char str[3];        for (int i=0; i<n; ++i) {scanf ("%i64d-%s", &a[i].len, str);    a[i].ch = str[0];        } for (int i=0; i<m; ++i) {scanf ("%i64d-%s", &b[i].len, str);    b[i].ch = str[0];    } n = Compress (A, n);    m = Compress (B, M);    ll ans = 0; if (m = = 1) {for (int i=0; i<n; ++i) {if (a[i].ch = = b[0].ch) {ans + = Std::max (0ll            , A[i].len-b[0].len + 1); }}} else if (M = = 2) {for (int i=0; i<n-1; ++i) {if (A[i] >= b[0] && a[i+1]        >= b[1]) ans++;    }} else {ans = KMP (a+1, N-2, b+1, m-2); } printf ("%i64d\n", ans); return 0;}

  

Codeforces Round #344 (Div. 2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.