• Codeforces Round #416 (Div. 2)


    A. Vladik and Courtesy

    At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.

    More formally, the guys take turns giving each other one candy more than they received in the previous turn.

    This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.

    Input

    Single line of input data contains two space-separated integers ab (1 ≤ a, b ≤ 109) — number of Vladik and Valera candies respectively.

    Output

    Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.

    Examples
    input
    1 1
    output
    Valera
    input
    7 6
    output
    Vladik
    Note

    Illustration for first test case:

    Illustration for second test case:

     题意:见图,文中的什么给对方瞎说的吧;

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
        int a,b;
        scanf("%d%d",&a,&b);
    
        int k = 1;
        while(true) {
            a-=k;
            if(a<0) {
                printf("Vladik
    ");
                break;
            }
           // b+=k;
            k++;
            b-=k;
            if(b<0) {
                printf("Valera
    ");
                break;
            }
           // a+=k;
            k++;
        }
    
        return 0;
    }
    View Code
    B. Vladik and Complicated Book

    Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.

    Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.

    Input

    First line contains two space-separated integers nm (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book.

    Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct.

    Each of the next m lines contains three space-separated integers lirixi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.

    Output

    For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.

    Examples
    input
    5 5
    5 4 3 2 1
    1 5 3
    1 3 1
    2 4 3
    4 4 4
    2 5 3
    output
    Yes
    No
    Yes
    Yes
    No
    input
    6 5
    1 4 3 2 5 6
    2 4 3
    1 6 2
    4 5 4
    1 3 3
    2 6 3
    output
    Yes
    No
    Yes
    No
    Yes
    Note

    Explanation of first test case:

    1. [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
    2. [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".
    3. [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".
    4. [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".
    5. [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".

    题意:求重排一个区间后,其中的一个数字是否变位置;

    大佬都写得主席树,不太会。

    暴力了;

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 const int maxn = 10000+5;
     6 
     7 
     8 
     9 int d[maxn];
    10 int a[maxn];
    11 
    12 int main()
    13 {
    14     //freopen("in.txt","r",stdin);
    15     int n,q;
    16     scanf("%d%d",&n,&q);
    17     for(int i=1;i<=n;i++) {
    18         scanf("%d",&a[i]);
    19     }
    20 
    21 
    22     while(q--) {
    23         int l,r,x;
    24         scanf("%d%d%d",&l,&r,&x);
    25         int sum = 0;
    26         for(int i=l;i<=r;i++) {
    27             if(a[i]<a[x])
    28                 sum++;
    29         }
    30 
    31         if(sum+l==x)
    32             puts("Yes");
    33         else puts("No");
    34     }
    35 
    36 
    37 
    38     return 0;
    39 }
    View Code
    C. Vladik and Memorable Trip

    Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:

    Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code ai is known (the code of the city in which they are going to).

    Train chief selects some number of disjoint segments of the original sequence of people (covering entire sequence by segments is not necessary). People who are in the same segment will be in the same train carriage. The segments are selected in such way that if at least one person travels to the city x, then all people who are going to city x should be in the same railway carriage. This means that they can’t belong to different segments. Note, that all people who travel to the city x, either go to it and in the same railway carriage, or do not go anywhere at all.

    Comfort of a train trip with people on segment from position l to position r is equal to XOR of all distinct codes of cities for people on the segment from position l to position rXOR operation also known as exclusive OR.

    Total comfort of a train trip is equal to sum of comfort for each segment.

    Help Vladik to know maximal possible total comfort.

    Input

    First line contains single integer n (1 ≤ n ≤ 5000) — number of people.

    Second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 5000), where ai denotes code of the city to which i-th person is going.

    Output

    The output should contain a single integer — maximal possible total comfort.

    Examples
    input
    6
    4 4 2 5 2 3
    output
    14
    input
    9
    5 1 3 1 5 2 4 2 5
    output
    9
    Note

    In the first test case best partition into segments is: [4, 4] [2, 5, 2] [3], answer is calculated as follows: 4 + (2 xor5) + 3 = 4 + 7 + 3 = 14

    In the second test case best partition into segments is: [3] [2, 4, 2] 5, answer calculated as follows: 3 + (2 xor 4) = 3 + 6 = 9.

    题意:将一个区间是否分成几块,但是,每一块中的数字必须全部包括,将区间里面的数异或起来。

    当时,我想到的状态dp(i,j),其实大部分的dp(i,j) ,都可以转换为d(i),那么预处理每一个值的左右区间,每一个区间的异或值。

    状态的转移:

    d(i) : 如果 i 是一个右端点,那么,划分为两个部分,注意中间的值,可以向前。

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 const int maxn = 5000 + 5;
     6 
     7 long long a[maxn];
     8 int l[maxn],r[maxn];
     9 long long st[maxn][maxn];
    10 int vis[maxn];
    11 long long dp[maxn];
    12 
    13 int main()
    14 {
    15     int n;
    16     scanf("%d",&n);
    17 
    18     for(int i=1;i<=n;i++) {
    19         scanf("%I64d",&a[i]);
    20         if(l[a[i]])
    21             l[a[i]]=min(l[a[i]],i);
    22         else
    23             l[a[i]]=i;
    24         if(r[a[i]])
    25             r[a[i]]=max(r[a[i]],i);
    26         else
    27             r[a[i]]=i;
    28     }
    29 
    30     for(int i=1; i<=n; i++)
    31     {
    32         memset(vis,0,sizeof(vis));
    33         st[i][i]=a[i];
    34         vis[a[i]]=1;
    35         for(int j=i+1; j<=n; j++)
    36         {
    37             if(!vis[a[j]])
    38             {
    39                 st[i][j]=st[i][j-1]^a[j];
    40                 vis[a[j]]=1;
    41             }
    42             else
    43             {
    44                 st[i][j]=st[i][j-1];
    45             }
    46         }
    47     }
    48 
    49 
    50     dp[0]=0;
    51     for(int i=1; i<=n; i++)
    52     {
    53         int temp = a[i];
    54         if(i==r[temp])
    55         {
    56             int L=l[temp];
    57             int ok=1;
    58             for(int j=l[temp]+1; j<r[temp]; j++)
    59             {
    60                 if(r[a[j]]>i)
    61                 {
    62                     ok=0;
    63                     break;
    64                 }
    65                 L=min(l[a[j]],L);
    66             }
    67             if(ok)
    68                 dp[i]=max(dp[i-1],dp[L-1]+st[L][i]);
    69             else
    70                 dp[i]=dp[i-1];
    71         }
    72         else
    73             dp[i]=dp[i-1];
    74     }
    75 
    76     printf("%I64d
    ",dp[n]);
    77 
    78 
    79     return 0;
    80 }
    View Code
  • 相关阅读:
    【笔记】隐式寻址方式(pending...)
    【笔记】有结构文件(pending...)
    【笔记】目录项(pending...)
    【笔记】主存储器
    Ubuntu 16.04 升级OpenSSH至7.7p1
    awk用法笔记
    find命令笔记
    VIM的使用
    Shell
    Linux文本处理三剑客
  • 原文地址:https://www.cnblogs.com/TreeDream/p/7199647.html
Copyright © 2020-2023  润新知