Codeforces Round #344 (Div. 2) 解题报告

来源:互联网 发布:股票价格提醒软件 编辑:程序博客网 时间:2024/05/29 03:12

631A- Interview


Blake is a CEO of a large company called “Blake Technologies”. He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.

We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, …, xr, where xi is the i-th element of the array x. You are given two arrays a and b of length n. You need to determine the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays.

The second line contains n integers ai (0 ≤ ai ≤ 109).

The third line contains n integers bi (0 ≤ bi ≤ 109).

Output
Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

input
5
1 2 4 3 2
2 3 3 12 1
output
22

input
10
13 2 7 11 8 4 9 8 5 1
5 7 18 9 2 3 0 11 8 6
output
46

题目链接:cf-631A

题目大意:给出a,b两个序列,分别求a,b任意一段连续的值或的最大值sum1,sum2.输出sum1+sum2

题目思路:或 全部的值即可,因为a | b = c ,c一定大于等于a,大于等于b

以下是代码:

#include <bits/stdc++.h>#define mst(a) memset(a,0,sizeof (a))#define FOR(i,n) for (int i = 0; i < n; i++)#define INF 1e9#define eps 1e-10using namespace std;typedef long long ll;ll a[1005],b[1005];int main(){    int n;    cin >> n;    ll sum1 = 0,sum2 = 0;    for (int i = 0; i < n; i++)    {        cin >> a[i];        sum1 = sum1 | a[i];    }    for (int i = 0; i < n; i++)    {        cin >> b[i];        sum2 = sum2 | b[i];    }    cout << sum1 + sum2 << endl;    return 0;}

631B-Print Check


Kris works in a large company “Blake Technologies”. As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.

Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.

Your program has to support two operations:

Paint all cells in row ri in color ai;
Paint all cells in column ci in color ai.
If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.

Your program has to print the resulting table after k operation.

Input
The first line of the input contains three integers n, m and k (1  ≤  n,  m  ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.

Each of the next k lines contains the description of exactly one query:

1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output
Print n lines containing m integers each — the resulting table after all operations are applied.

input
3 3 3
1 1 3
2 2 1
1 2 2
output
3 1 3
2 2 2
0 1 0

input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
output
1 1 1
1 0 1
1 1 1
1 0 1
1 1 1

题目链接:cf-631B

题目大意:给出n*m的格子,初始填充颜色为0,有k次操作,每次输入a,b,val,有两种选择

  1. a == 1; 把第b行全部改为颜色val
  2. a == 2; 把第b列全部改为颜色val

题目思路:本来的想法是用二维线段树,可是写不出来。。然后直接暴力,初测过了,但是终测没过,意料之中orz

以行为例:

每次修改,将r[b] = val; // 修改第b行的颜色为val

另外,记录这次修改的操作是第几次。 // 后面修改的颜色会覆盖原来的颜色

列同理。

最后处理的时候,第i行第j列的元素,比较第i行最后一次修改在第几次,和第j列最后一次修改在第几次。较大的为答案。

以下是代码:

#include <bits/stdc++.h>#define mst(a) memset(a,0,sizeof (a))#define FOR(i,n) for (int i = 0; i < n; i++)#define INF 1e9#define eps 1e-10using namespace std;typedef long long ll;int r[5005],c[5005],ret1[5005],ret2[5005];int main(){    int n,m,k;    cin >> n >> m >> k;    for (int i = 1; i <= k; i++)  //从1开始     {        int a,b,val;        cin >> a >> b >> val;        if (a == 1)        {            r[b] = val;            ret1[b] = i;  //记录行上最后一次改变的i的值         }        else        {            c[b] = val;            ret2[b] = i;        }    }    for (int i = 1; i <= n; i++)    {        for (int j = 1; j <= m; j++)        {            if (ret1[i] > ret2[j]) cout << r[i] << " ";  //输出第i行的值             else cout << c[j] << " ";  //输出第j列的值         }        cout << endl;    }    return 0;}

631C-Report


Each month Blake gets the report containing main economic indicators of the company “Blake Technologies”. There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands of m managers. Each of them may reorder the elements in some order. Namely, the i-th manager either sorts first ri numbers in non-descending or non-ascending order and then passes the report to the manager i + 1, or directly to Blake (if this manager has number i = m).

Employees of the “Blake Technologies” are preparing the report right now. You know the initial sequence ai of length n and the description of each manager, that is value ri and his favourite order. You are asked to speed up the process and determine how the final report will look like.

Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of commodities in the report and the number of managers, respectively.

The second line contains n integers ai (|ai| ≤ 109) — the initial report before it gets to the first manager.

Then follow m lines with the descriptions of the operations managers are going to perform. The i-th of these lines contains two integers ti and ri (, 1 ≤ ri ≤ n), meaning that the i-th manager sorts the first ri numbers either in the non-descending (if ti = 1) or non-ascending (if ti = 2) order.

Output
Print n integers — the final report, which will be passed to Blake by manager number m.

input
3 1
1 2 3
2 2
output
2 1 3

input
4 2
1 2 4 3
2 3
1 2
output
2 4 1 3

题目链接:cf-631C

题目大意:给一个序列,m次操作,每次形如:把[1,ri]按升序/降序排列。求最终序列。

题目思路:这道题,我还没能解决

参考博客:here

0 0
原创粉丝点击