虽然感觉是不太对的做法,但总算是手切了 OI 萌新的第二道黑…
题意
给定一个边长为 的方阵和 次询问,每次询问可能是以下两种情形:
-
向 处添加一个权值为 的点;
-
求矩形区域 中的所有点权的第 大值。
强制在线。
解法
注意到:
-
;
-
没有初始点;
所以考虑 vector 乱搞。
具体地来说,对于询问 1,直接向 vector 中以 为关键字插入,此时 vector 是 -有序的;
对于询问 2,从 vector 的尾部开始计 个在对应区域内的点。
AC Code
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+9;
int ans,q,opt,x_1,y_1,x_2,y_2,_k;
struct node{
int x,y,k;
bool operator< (const node& other) const{
return k<other.k;
}
};
vector<node> a;
void decrypt(vector<int*> v){
for(auto at:v) *at^=ans;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
a.reserve(N);
cin>>opt>>q;
while(q--){
cin>>opt;
if(opt==1){
cin>>x_1>>y_1>>_k;
decrypt({&x_1,&y_1,&_k});
node nd={x_1,y_1,_k};
a.insert(upper_bound(a.begin(),a.end(),nd),nd);
}
else{
cin>>x_1>>y_1>>x_2>>y_2>>_k;
decrypt({&x_1,&y_1,&x_2,&y_2,&_k});
int i=a.size();
while(~--i&&_k){
_k-=(a[i].x>=x_1&&a[i].y>=y_1&&a[i].x<=x_2&&a[i].y<=y_2);
}
if(_k){
cout<<"NAIVE!ORZzyz.\n";
ans=0;
continue;
}
ans=a[i+1].k;
cout<<ans<<'\n';
}
}
return 0;
}复杂度分析
时间复杂度 ,空间复杂度 。