G 求调/证思路是错的
  • 板块学术版
  • 楼主Snoozing_QAQ
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/11 22:18
  • 上次更新2025/1/12 12:18:10
查看原帖
G 求调/证思路是错的
703919
Snoozing_QAQ楼主2025/1/11 22:18

思路:

把每个询问转变为:有一个区间[s,t],求一个阈值k,使得a[s+t-k]+s+t-k>=s

#include<bits/stdc++.h>
#define Snoozing_QwQ using
#define AK namespace
#define ABC std;
Snoozing_QwQ AK ABC
#undef Snoozing_QwQ
#undef AK
#undef ABC
#define int long long
#pragma GCC optimize("O1,O2,O3,O4,O5,Og,Os,Ofast,inline,-ffast-math")
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define updg(x,y) (x>(y)?(x = y):x)
#define updl(x,y) (x<(y)?(x = y):x)
const string ansstrbs[] = {"No\n","Yes\n"};
const string ansstrss[] = {"no\n","yes\n"};
const string ansstrbb[] = {"NO\n","YES\n"};
#define lowbit(x) ((x)&(-(x)))
#define fors(i,s,t,step) for(int i = s;i<=t;i+=step)

//#define debug
//#define pair

#ifdef pair
#undef pair
#define pii pair<int,int>
#define fir first
#define sec second
#define mkp make_pair
#endif
int n;
int a[200005],b[200005];
bool check(int s,int t,int k){
    return a[s+t-k]+s+t-k>=s;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
#ifdef debug
	cin >> T;
#endif
    while(T--){
    	cin >> n;
        for(int i = 1;i<=n;i++) cin >> b[i];
        for(int i = 1;i<=n;i++) a[i] = upper_bound(b+1,b+1+n,b[i]/2)-b-1-i;
        //有一个区间[s,t]和一个阈值k,问a[s+t-k]+s+t-k是否>=s
        int q;
        cin >> q;
        while(q--){
            int s,t,l,r,mid,ans;
            cin >> s >> t;
            l = s,r = s-1+((t-s+1)>>1),ans = s-1;
            while(l<=r){
                mid = (l+r)>>1;
                if(check(s,t,mid)) l = mid+1,ans = mid;
                else r = mid-1;
            }
            cout << ans-s+1 << "\n";
        }
	}
	return 0;
} 
2025/1/11 22:18
加载中...