A - Interview CodeForces - 631A
#include<bits/stdc++.h>
using namespace std;
int a[1005],b[1005];
int main(){
int n;
scanf("%d",&n);
int suma=0,sumb=0,x;
for(int i=0;i<n;++i){
scanf("%d",&x);
suma|=x;
}
for(int i=0;i<n;++i){
scanf("%d",&x);
sumb|=x;
}
printf("%d\n",suma+sumb);
}
B - Print Check CodeForces - 631B
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int r[5005],c[5005],tr[5005],tc[5005],a;
int main(){
int n,m,k,d,x;
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=k;++i){
scanf("%d%d%d",&d,&x,&a);
if(d==1){
r[x]=a;
tr[x]=i;
}
else{
c[x]=a;
tc[x]=i;
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(tr[i]>tc[j]) printf("%d ",r[i]);
else printf("%d ",c[j]);
}
printf("\n");
}
printf("\n");
}
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool cmp(int a,int b){
return a>b;
}
stack<int>p;
int n,m;
int num[200005],ans[200005];
struct node{
int r;
int t;
}op[200005];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
scanf("%d",&num[i]);
}
for(int i=1;i<=m;++i){
scanf("%d%d",&op[i].t,&op[i].r);
}
p.push(0);
for(int i=m;i>=1;--i){
if(op[i].r>op[p.top()].r){//单调递减栈
p.push(i);
//cout<<"push "<<i<<" "<<op[i].r<<" "<<op[i].t<<endl;
}
}
int l=1;
int r=op[p.top()].r;
for(int i=r+1;i<=n;++i){//后面的数没有操作,直接复制过来
ans[i]=num[i];
}
int nowr=r;//op[p.top()].r
int nowt=op[p.top()].t;
sort(num+1,num+r+1);
p.pop();
while(!p.empty()){
int nextr=op[p.top()].r;
int nextt=op[p.top()].t;
//cout<<"r="<<nowr<<"t="<<nowt<<endl;
for(int i=nowr;i>nextr;--i){
if(nowt==1)ans[i]=num[r--];
else ans[i]=num[l++];//优秀
}
nowr=nextr;
nowt=nextt;
p.pop();
}
for(int i=1;i<=n;++i)
printf("%d ",ans[i]);
printf("\n");
return 0;
}