题解:AT_abc466_c [ABC466C] Count Close Pairs
题目链接:AT_abc466_c
C 就出交互题何意味。
题目大意
已知数轴上有
求有多少个点对之间的距离不超过
大致思路
点的编号是从左往右单调递增的,故考虑双指针,枚举右端点
具体地,初始时我们令
最终代码
#include <bits/stdc++.h>
using namespace std;
int n,ans;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n;
int l=1;
for(int r=2;r<=n;r++)
{
while(l<r)
{
cout<<"? "<<l<<' '<<r<<endl;
string s;cin>>s;
if(s=="Yes") break;
l++;
}
ans+=r-l;
}
cout<<"! "<<ans<<endl;
return 0;
}
时间复杂度:
空间复杂度: