对于想了解ecnu2951Bitoperation的读者,本文将是一篇不可错过的文章,并且为您提供关于C#Collectionwasmodified;enumerationoperationmayno
对于想了解ecnu 2951 Bit operation的读者,本文将是一篇不可错过的文章,并且为您提供关于C# Collection was modified;enumeration operation may not execute、CF1295E Permutation Separation、Couldn''t find log associated with operation handle: OperationHandle [opType=EXECUTE_STATEMENT...、D - Xenia and Bit Operations的有价值信息。
本文目录一览:- ecnu 2951 Bit operation
- C# Collection was modified;enumeration operation may not execute
- CF1295E Permutation Separation
- Couldn''t find log associated with operation handle: OperationHandle [opType=EXECUTE_STATEMENT...
- D - Xenia and Bit Operations
ecnu 2951 Bit operation
#include<bits/stdc++.h> using namespace std; const unsigned int u=2147483648; int main(){ unsigned int n; int m; cin>>n>>m; while(m--){ if(n&1)n=(n>>1)|u; else n>>=1; } cout<<n; }
C# Collection was modified;enumeration operation may not execute
一、问题描述
在做 数组、列表、集合遍历时,可能我们会遇见这个问题。Collection was modified;enumeration operation may not execute ,翻译的中文意思:集合已修改;枚举操作可能无法执行。
二、解决方案
就是在遍历时,不要改变正在遍历的集合即可,您可以先遍历完在对其进行操作。
三、案例
出现问题前的代码如下,就是我在遍历 items 的同时,又往 items 中 add 数据。
public async Task<ListResultDto<RecordBookListDto>> GetFlatRecordBookItems()
{
var query = _recordBookRepository
.GetAll();
var entities = await query.ToListAsync();
var items = new List<RecordBookListDto>();
foreach (var entity in entities)
{
var dto = entity.MapTo<RecordBookListDto>();
items.Add(dto);
}
//todo 获取测点编号
foreach (var item in items)
{
if (!string.IsNullOrEmpty(item.DataId))
{
String[] array = item.DataId.Replace("[", "").Replace("]", "").Replace("\"", "").Split('','');
foreach (var ar in array)
{
var ins = _instrumentGroupRepository.Get(Guid.Parse(ar));
var l = new RecordBookListDto();
l.Id = Guid.Parse(ar);
l.ParentId = item.Id.ToString();
l.Name = ins.No;
items.Add(l);
}
}
}
var listDto = new ListResultDto<RecordBookListDto>(items);
return listDto;
}
修改完成后的代码:
public async Task<ListResultDto<RecordBookListDto>> GetFlatRecordBookItems()
{
var query = _recordBookRepository
.GetAll();
var entities = await query.ToListAsync();
var items = new List<RecordBookListDto>();
foreach (var entity in entities)
{
var dto = entity.MapTo<RecordBookListDto>();
items.Add(dto);
}
List<RecordBookListDto> newItems = new List<RecordBookListDto>();
//todo 获取测点编号
foreach (var item in items)
{
if (!string.IsNullOrEmpty(item.DataId))
{
String[] array = item.DataId.Replace("[", "").Replace("]", "").Replace("\"", "").Split('','');
foreach (var ar in array)
{
var ins = _instrumentGroupRepository.Get(Guid.Parse(ar));
var l = new RecordBookListDto();
l.Id = Guid.Parse(ar);
l.ParentId = item.Id.ToString();
l.Name = ins.No;
newItems.Add(l);
}
}
}
foreach (var item in newItems)
{
items.Add(item);
}
var listDto = new ListResultDto<RecordBookListDto>(items);
return listDto;
CF1295E Permutation Separation
我的blog
题目链接:CF1295E Permutation Separation
$$preface$$
本文版权归博客园,洛谷博客和蒟蒻wjr所有,欢迎转载,但需保留此段声明,并给出原文链接,如有侵权行为,还请不吝啬向博主举报,谢谢合作。
开一波E题闷声发大财
感谢@Karry5307 在考后提供思路
$$description$$
给定一个序列$p$(为1~n的排列),和这个序列每一个数所对应的花费a以及序列的长度n。
取一数$1\leq k<n$,将$p$序列分成两个序列,分别是$p_1,p_2,...,p_k$和$p_{k+1},p_{k+2},...,p_n$
将两个序列的某些数移到另一个序列使得第一个序列的所有数小于第二个序列的所有数,注意如果其中一组为空,则满足此条件,移动$p_i$的花费是$a_i$
求最小花费 $$solution$$ 一道裸的线段树
考虑维护$a_i$的前缀和$sum_i=\sum_{j=1}^{i}a_i$,因为$1\leq k<n$,所以前缀和$sum$最多只要维护到$a_{n-1}$即可
假设第一个序列的所有数都移到了第二个序列值最小虽然不大可能则 答案是$sum$中的最小值
因为$p$序列是1~n的排列,所以记$pos_i$为$i$在序列$p$中出现的位置
枚举i从1~n
假设将$p[pos_i]$最终在第一序列,那么$p[pos_1],p[pos_2],...,,p[pos_{i-1}]一定在最终在第一序列$,考虑当前对前缀和的修改。
当$k>=pos_i$时,$p[pos_i]$在第一序列,那么不需要费用
当$k<pos_i$时,$p[pos_i]$在第二序列,需要$a[pos_i]$的费用移动到第一序列
则将$sum_1$~$sum_{pos_i-1}$的值分别加上$a[pos_i]$
$sum_{pos_i}$~$sum_{n-1}$的值分别减去$a[pos_i]$
当前策略最小值即当前$sum$的最小值。
答案即是对所有策略的最小值取最小值
$$code$$
#include <cstdio>
#include <algorithm>
#define re register
#define ll long long
#define lc (root<<1)
#define rc (root<<1|1)
using namespace std;
template<typename T>
inline void read(T&x)
{
x=0;
char s=(char)getchar();
bool flag=false;
while(!(s>=''0''&&s<=''9''))
{
if(s==''-'')
flag=true;
s=(char)getchar();
}
while(s>=''0''&&s<=''9'')
{
x=(x<<1)+(x<<3)+s-''0'';
s=(char)getchar();
}
if(flag)
x=(~x)+1;
return;
}
const int N=2e5+5;
struct Tree
{
ll minn,lazy;
} tree[N<<2];
ll sum[N];
inline void build(int root,int l,int r)
{
if(l==r)
{
tree[root].minn=sum[l];
tree[root].lazy=0;
return;
}
int mid=(l+r)>>1;
build(lc,l,mid);
build(rc,mid+1,r);
tree[root].minn=min(tree[lc].minn,tree[rc].minn);
return;
}
inline void pushdown(int root)
{
if(!tree[root].lazy)
return;
tree[lc].minn+=tree[root].lazy;
tree[rc].minn+=tree[root].lazy;
tree[lc].lazy+=tree[root].lazy;
tree[rc].lazy+=tree[root].lazy;
tree[root].lazy=0;
return;
}
inline void change(int root,int l,int r,int x,int y,int val)
{
if(r<x||l>y)
return;
if(x<=l&&r<=y)
{
tree[root].minn+=val;
tree[root].lazy+=val;
return;
}
int mid=(l+r)>>1;
pushdown(root);
change(lc,l,mid,x,y,val);
change(rc,mid+1,r,x,y,val);
tree[root].minn=min(tree[lc].minn,tree[rc].minn);
return;
}
int n,p[N],a[N],pos[N];
ll ans;
int main()
{
read(n);
for(re int i=1; i<=n; ++i)
{
read(p[i]);
pos[p[i]]=i;
}
for(re int i=1; i<=n; ++i)
{
read(a[i]);
sum[i]=sum[i-1]+a[i];
}
build(1,1,n-1);
ans=tree[1].minn;
for(re int i=1; i<=n; ++i)
{
change(1,1,n-1,1,pos[i]-1,a[pos[i]]);
change(1,1,n-1,pos[i],n-1,-a[pos[i]]);
// printf("%d\n",ans);
ans=min(ans,tree[1].minn);
}
printf("%lld\n",ans);
return 0;
}
Couldn''t find log associated with operation handle: OperationHandle [opType=EXECUTE_STATEMENT...
这个异常的出现是因为 hive-site-xml 中的 hive.server2.logging.operation.log.location 属性未配置正确:
修改为:
<property>
<name>hive.server2.logging.operation.log.location</name>
<value>D:/apache-hive-2.1.1-bin/hive/iotmp/operation_logs</value>
<description>Top level directory where operation logs are stored if logging functionality is enabled</description>
</property>
D:/apache-hive-2.1.1-bin/hive/iotmp 需要在 hadoop 中进行创建配置。
D - Xenia and Bit Operations
Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value v for a.
Namely, it takes several iterations to calculate value v. At the first iteration, Xenia writes a new sequence a1 or a2, a3 or a4, ..., a2n - 1 or a2n, consisting of 2n - 1 elements. In other words, she writes down the bit-wise OR of adjacent elements of sequence a. At the second iteration, Xenia writes the bitwise exclusive OR of adjacent elements of the sequence obtained after the first iteration. At the third iteration Xenia writes the bitwise OR of the adjacent elements of the sequence obtained after the second iteration. And so on; the operations of bitwise exclusive OR and bitwise OR alternate. In the end, she obtains a sequence consisting of one element, and that element is v.
Let''s consider an example. Suppose that sequence a = (1, 2, 3, 4). Then let''s write down all the transformations (1, 2, 3, 4) → (1 or 2 = 3, 3 or 4 = 7) → (3 xor 7 = 4). The result is v = 4.
You are given Xenia''s initial sequence. But to calculate value v for a given sequence would be too easy, so you are given additional mqueries. Each query is a pair of integers p, b. Query p, b means that you need to perform the assignment ap = b. After each query, you need to print the new value v for the new sequence a.
The first line contains two integers n and m (1 ≤ n ≤ 17, 1 ≤ m ≤ 105). The next line contains 2n integers a1, a2, ..., a2n (0 ≤ ai < 230). Each of the next m lines contains queries. The i-th line contains integers pi, bi (1 ≤ pi ≤ 2n, 0 ≤ bi < 230) — the i-th query.
Print m integers — the i-th integer denotes value v for sequence a after the i-th quer
线段树(刚学线段树拿过来练练手
关于ecnu 2951 Bit operation的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于C# Collection was modified;enumeration operation may not execute、CF1295E Permutation Separation、Couldn''t find log associated with operation handle: OperationHandle [opType=EXECUTE_STATEMENT...、D - Xenia and Bit Operations等相关内容,可以在本站寻找。
本文标签: