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,有两种选择
- a == 1; 把第b行全部改为颜色val
- 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
- Codeforces Round #344 (Div. 2) 解题报告
- 【解题报告】Codeforces Round #344 (Div. 2)
- Codeforces Round #149 (Div. 2)解题报告
- Codeforces Round #180 (Div. 2) 解题报告
- Codeforces Round #190 (Div. 2) 解题报告
- Codeforces Round #191 (Div. 2) 解题报告
- Codeforces Round #189 (Div. 2) 解题报告
- Codeforces Round #142 (Div. 2) 解题报告
- Codeforces Round #229 (Div. 2) 解题报告
- Codeforces Round #241 (Div. 2) 解题报告
- Codeforces Round #262 (Div. 2)解题报告
- Codeforces Round #267 (Div. 2) 解题报告
- Codeforces Round #266 (Div. 2)解题报告
- Codeforces Round #268 (Div. 2) 解题报告
- Codeforces Round #271 (Div. 2) 解题报告
- Codeforces Round #274 (Div. 2) 解题报告
- Codeforces Round #276 (Div. 2) 解题报告
- Codeforces Round #277 (Div. 2) 解题报告
- Android Studio 使用GitHub进行版本控制
- C#多线程与异步的区别
- 安卓计算APK的应用大小、数据大小、缓存大小等。
- Android 组播技术学习
- c++常用设计模式实现
- Codeforces Round #344 (Div. 2) 解题报告
- bzoj1092 蜘蛛难题 模拟
- diference between support vectors and boundary vectors.
- 标志寄存器一点细节
- 数据结构之“Ordered List and Sorted List”(二)
- Linux下Gcc生成和使用静态库和动态库详解
- instancetype和id
- 转自程先的专栏:如果是初学C语言请看完 一些成功人士的心得
- Java HashMap遍历实践