rt,在其他OJ和本地运行样例一都没问题,但提交就全TLE,不开O2就RE。
思路:用把深度大于s的块置1,旁边也有1就联通在一起,并查集来维护连通块最大长度,某个鞋子能通过必须大于它。
int a[]:雪地深度,PII c[]升序雪地深度和编号 b[] 深度s,步长d,编号id
#include<bits/stdc++.h>
#include<unordered_map>
typedef long long ll;
typedef long double ld;
#define debug(a) cout<<a<<'\n'
#define Pll pair<ll,ll>
#define PII pair<int,int>
#define ft first
#define sd second
#define vec vector
#define pushk push_back
#define pl p<<1
#define pr p<<1|1
using namespace std;
const int N = 1e5+ 10, M = 300, mod = 1e6;
const ll inf = 1e18;
const ld eps = 1e-8;
int mov[4][2] = { {0,1},{1,0},{-1,0},{0,-1} }, dx, dy;
void bout(bool f) {
if (f)cout << "Yes\n";
else cout << "No\n";
}
ll n, m, k;
int a[N],ans[N];
PII c[N];
struct node{
int s,d,id;
bool operator<(const node n)const {
return s<n.s;
}
};
node b[N];
int fa[N],rk[N];
int find(int x){
if(x==fa[x])return x;
else return fa[x]=find(fa[x]);
}
bool unite(int x,int y){
x=find(x);
y=find(y);
if(x==y)return 0;
rk[x]+=rk[y];
fa[y]=x;
}
bool st[N];
void solve(){
cin>>n>>m;
for(int i=1;i<=n;++i){
fa[i]=i;
rk[i]=1;
}
for(int i=1;i<=n;++i){
cin>>a[i];
c[i]={a[i],i};
}
sort(c+1,c+n+1);
for(int i=1;i<=m;++i){
cin>>b[i].s>>b[i].d;
b[i].id=i;
}
sort(b+1,b+m+1);
int p=n,res=0,x,id;
for(int i=m;i>=1;--i){
while(b[i].s<c[p].ft){
id=c[p].sd;
--p;
st[id]=1;
if(st[id-1])unite(id,id-1);
if(st[id+1])unite(id,id+1);
res=max(res,rk[find(id)]);
}
if(b[i].d>res)ans[b[i].id]=1;
else ans[b[i].id]=0;
}
for(int i=1;i<=m;++i)cout<<ans[i]<<'\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
streambuf* cinbackup = cin.rdbuf(), * coutbackup = cout.rdbuf();
ifstream fin("in.txt");
ofstream fout("out.txt");
cin.rdbuf(fin.rdbuf());
cout.rdbuf(fout.rdbuf());
#endif
int _ = 1, __ = 1;
//cin >> _;
__ = _;
while (_--) {
solve();
}
return 0;
}