题意:给定n个国家,k个地区,aij为第i个国家第j个地区,bij=a1j|a2j|---aij为第i个国家第j个地区的更新值,给出q个问题,每个问题包含m项要求,国家i必须满足m项要求:如果o=='<'必须满足bir<c否则bir>c,输出满足所有条件的最小序号的国家
分析:如果o是小于号,用二分找到右区间,如果o是大于号,用二分找到左区间左区间,找到满足条件的区间最后取最小值即可
代码:
```
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void sol(){
int n,k,q;cin>>n>>k>>q;
ll a[n+10][k+10];
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
cin>>a[i][j];
}
}
for(int j=1;j<=k;j++){
for(int i=2;i<=n;i++){
a[i][j]=a[i-1][j]|a[i][j];
}
}
int rr;char o;ll c;
for(int i=1;i<=q;i++){
int m;cin>>m;
int l=1,r=n;int f=0;
for(int j=1;j<=m;j++){
cin>>rr>>o>>c;
int l1=l,r1=r;
if(o=='<'){//
int l2=l,r2=r;
while(l2<r2){//右
int mid=(l2+r2+1)/2;
if((a[mid][rr]<c&&o=='<')||(a[mid][rr]>c&&o=='>'))l2=mid;
else r2=mid-1;
}
if(l2==l){
if((a[l2][rr]<c&&o=='<')||(a[l2][rr]>c&&o=='>'))l2=l;
else f=1;
}
r=l2;
}
else{
while(l1<r1){//左
int mid=(l1+r1)/2;
if((a[mid][rr]<c&&o=='<')||(a[mid][rr]>c&&o=='>'))r1=mid;
else l1=mid+1;
}
if(l1==r){
if((a[l1][rr]<c&&o=='<')||(a[l1][rr]>c&&o=='>'))l1=r;
else f=1;
}
l=l1;
}
}
if(f==0)cout<<l<<endl;
else cout<<"-1"<<endl;
}
}
int main() {
int t=1;
while(t--)sol();
return 0;
}
```
##
标签:Reverse,rr,int,mid,Rivers,l2,l1,else,CF984 From: https://blog.csdn.net/m0_74310050/article/details/143535322