CF edu 168 题解
1.「杂题乱刷」CF1916C2.「比赛总结」CF Round 921 Div.2 比赛总结3.「比赛总结」CF Round 909 Div 3 比赛总结4.「比赛总结」CF Round 915 Div 2 比赛总结5.「杂题乱刷」CF1914E1 & CF1914E26.「杂题乱刷」CF978G7.「杂题乱刷」CF961B8.「杂题乱刷」CF1105C9.「杂题乱刷」CF1620E10.「杂题乱刷」CF1272D11.「杂题乱刷」CF1904B12.「杂题乱刷」CF1534C13.「杂题乱刷」CF283A14.「杂题乱刷」CF468A15.「杂题乱刷」CF1585B16.「杂题乱刷」CF1221B17.「杂题乱刷」CF624B18.「杂题乱刷」CF1925C & CF1924A19.「杂题乱刷」CF1927D20.「杂题乱刷」CF1886D21.「杂题乱刷」CF954C22.「杂题乱刷」CF1937C & CF1936A23.「杂题乱刷」CF1934D224.「杂题乱刷」CF1846E1 & CF1846E225.「杂题乱刷」CF74E26.「杂题乱刷」CF786C27.「比赛总结」CF Round 834 Div.3 比赛总结28.「杂题乱刷」CF1973D29.「杂题乱刷」CF1759F30.「杂题乱刷」CF1650D31.「杂题乱刷」CF1650E32.「杂题乱刷」CF1977B33.「杂题乱刷」CF1977C34.「杂题乱刷」CF460C35.「杂题乱刷」CF1979C36.「杂题乱刷」CF1985F37.「杂题乱刷」CF1987C38.「杂题乱刷」CF1987D39.「杂题乱刷2」CF607B40.「杂题乱刷2」CF1702F41.「杂题乱刷2」CF1454F Array Partition42.「杂题乱刷2」CF402D Upgrading Array43.「杂题乱刷2」CF1506E Restoring the Permutation44.「杂题乱刷2」CF727D45.「杂题乱刷2」CF1015D Walking Between Houses46.「杂题乱刷2」CF1615C Menorah47.「杂题乱刷2」CF1513C48.「杂题乱刷2」CF1889A Qingshan Loves Strings 249.「杂题乱刷2」CF1996F
50.CF edu 168 题解
51.「杂题乱刷2」CF1486C1 & CF1486C252.CF1999题解53.「杂题乱刷2」CF1183E & CF1183H54.「杂题乱刷2」CF1567D55.「杂题乱刷2」CF1493C56.「杂题乱刷2」CF1360H57.「杂题乱刷2」CF862C58.「杂题乱刷2」CF862D59.「杂题乱刷2」CF1365G60.「杂题乱刷2」CF1301C61.「杂题乱刷2」CF1527B262.「杂题乱刷2」CF1108E263.「杂题乱刷2」CF827B64.「杂题乱刷2」CF1839E65.「杂题乱刷2」CF1433F66.「杂题乱刷2」CF1227D267.「杂题乱刷2」CF1372D68.「杂题乱刷2」CF2036G69.「杂题乱刷2」CF1370F270.「杂题乱刷2」CF1354E71.「杂题乱刷2」CF1219G72.「杂题乱刷2」CF1288E73.「杂题乱刷2」CF2038B74.「杂题乱刷2」CF2040D75.「杂题乱刷2」CF1896E76.「杂题乱刷2」CF2066B77.「杂题乱刷2」CF2067C78.「杂题乱刷2」CF1738E Balance Addicts79.「杂题乱刷2」CF1738F Connectivity Addicts80.「杂题乱刷2」CF109DA
直接找两个相同的字符往里面塞个不同的字符即可。
点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
打 cf 不要用 umap!!!
记住,rating 是身外之物。
该冲正解时冲正解!
Problem:
算法:
思路:
*/
#include<bits/stdc++.h>
using namespace std;
//#define map unordered_map
#define re register
#define ll long long
#define forl(i,a,b) for(re ll i=a;i<=b;i++)
#define forr(i,a,b) for(re ll i=a;i>=b;i--)
#define forll(i,a,b,c) for(re ll i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(re ll i=a;i>=b;i-=c)
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);init();
#define endl '\n'
#define QwQ return 0;
#define db long double
#define ull unsigned long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
#define x first
#define y second
#define aty cout<<"Yes\n";
#define atn cout<<"No\n";
#define cfy cout<<"YES\n";
#define cfn cout<<"NO\n";
#define xxy cout<<"yes\n";
#define xxn cout<<"no\n";
#define printcf(x) x?cout<<"YES\n":cout<<"NO\n";
#define printat(x) x?cout<<"Yes\n":cout<<"No\n";
#define printxx(x) x?cout<<"yes\n":cout<<"no\n";
#define maxqueue priority_queue<ll>
#define minqueue priority_queue<ll,vector<ll>,greater<ll>>
void Max(ll&x,ll y){x=max(x,y);}
void Min(ll&x,ll y){x=min(x,y);}
ll _t_;
void _clear(){}
void solve()
{
_clear();
string s;
cin>>s;
ll n=s.size();
s=' '+s;
forl(i,1,n-1)
{
if(s[i]==s[i+1])
{
if(s[i]=='a')
{
forl(j,1,i)
cout<<s[j];
cout<<'b';
forl(j,i+1,n)
cout<<s[j];
cout<<endl;
}
else
{
forl(j,1,i)
cout<<s[j];
cout<<'a';
forl(j,i+1,n)
cout<<s[j];
cout<<endl;
}
return ;
}
}
forl(i,1,n)
cout<<s[i];
if(s[n]=='a')
cout<<'b';
else
cout<<'a';
cout<<endl;
}
void init(){}
int main()
{
IOS;
_t_=1;
cin>>_t_;
while(_t_--)
solve();
QwQ;
}
B
直接暴力判断用前缀和维护即可。
点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
打 cf 不要用 umap!!!
记住,rating 是身外之物。
该冲正解时冲正解!
Problem:
算法:
思路:
*/
#include<bits/stdc++.h>
using namespace std;
//#define map unordered_map
#define re register
#define ll long long
#define forl(i,a,b) for(re ll i=a;i<=b;i++)
#define forr(i,a,b) for(re ll i=a;i>=b;i--)
#define forll(i,a,b,c) for(re ll i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(re ll i=a;i>=b;i-=c)
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);init();
#define endl '\n'
#define QwQ return 0;
#define db long double
#define ull unsigned long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
#define x first
#define y second
#define aty cout<<"Yes\n";
#define atn cout<<"No\n";
#define cfy cout<<"YES\n";
#define cfn cout<<"NO\n";
#define xxy cout<<"yes\n";
#define xxn cout<<"no\n";
#define printcf(x) x?cout<<"YES\n":cout<<"NO\n";
#define printat(x) x?cout<<"Yes\n":cout<<"No\n";
#define printxx(x) x?cout<<"yes\n":cout<<"no\n";
#define maxqueue priority_queue<ll>
#define minqueue priority_queue<ll,vector<ll>,greater<ll>>
void Max(ll&x,ll y){x=max(x,y);}
void Min(ll&x,ll y){x=min(x,y);}
ll _t_;
void _clear(){}
ll n;
ll pd;
string s[10];
ll sum[200010],sum2[200010];
ll sum3[200010],sum4[200010];
void solve()
{
pd=1;
_clear();
cin>>n>>s[1]>>s[2];
forl(i,0,n+2)
sum[i]=sum2[i]=sum3[i]=sum4[i]=0;
s[1]=' '+s[1];
s[2]=' '+s[2];
forl(j,1,2)
forl(i,1,n)
pd&=s[j][i]=='x';
forl(i,1,n)
sum[i]|=s[1][i]=='.',sum2[i]=sum[i];
forl(i,1,n)
sum[i]|=sum[i-1];
forr(i,n,1)
sum2[i]|=sum2[i+1];
forl(i,1,n)
sum3[i]|=s[2][i]=='.',sum4[i]=sum3[i];
forl(i,1,n)
sum3[i]|=sum3[i-1];
forr(i,n,1)
sum4[i]|=sum4[i+1];
if(pd==1)
{
cout<<0<<endl;
return ;
}
ll ans=0;
forl(i,1,n)
if(s[2][i-1]=='x' && s[2][i]=='.' && s[2][i+1]=='x' && (sum[i-1] || sum3[i-2]) && (sum2[i+1] || sum4[i+2]))
ans++;
forl(i,1,n)
if(s[1][i-1]=='x' && s[1][i]=='.' && s[1][i+1]=='x' && (sum[i-2] || sum3[i-1]) && (sum2[i+2] || sum4[i+1]))
ans++;
cout<<ans<<endl;
}
void init(){}
int main()
{
IOS;
_t_=1;
cin>>_t_;
while(_t_--)
solve();
QwQ;
}
C
右括号合法情况下能放就放,剩余情况放左括号即可。
点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
打 cf 不要用 umap!!!
记住,rating 是身外之物。
该冲正解时冲正解!
Problem:
算法:
思路:
*/
#include<bits/stdc++.h>
using namespace std;
//#define map unordered_map
#define re register
#define ll long long
#define forl(i,a,b) for(re ll i=a;i<=b;i++)
#define forr(i,a,b) for(re ll i=a;i>=b;i--)
#define forll(i,a,b,c) for(re ll i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(re ll i=a;i>=b;i-=c)
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);init();
#define endl '\n'
#define QwQ return 0;
#define db long double
#define ull unsigned long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
#define x first
#define y second
#define aty cout<<"Yes\n";
#define atn cout<<"No\n";
#define cfy cout<<"YES\n";
#define cfn cout<<"NO\n";
#define xxy cout<<"yes\n";
#define xxn cout<<"no\n";
#define printcf(x) x?cout<<"YES\n":cout<<"NO\n";
#define printat(x) x?cout<<"Yes\n":cout<<"No\n";
#define printxx(x) x?cout<<"yes\n":cout<<"no\n";
#define maxqueue priority_queue<ll>
#define minqueue priority_queue<ll,vector<ll>,greater<ll>>
void Max(ll&x,ll y){x=max(x,y);}
void Min(ll&x,ll y){x=min(x,y);}
ll _t_;
void _clear(){}
ll n;
ll pd;
string s[10];
ll sum[200010],sum2[200010];
ll sum3[200010],sum4[200010];
void solve()
{
pd=1;
_clear();
cin>>n>>s[1]>>s[2];
forl(i,0,n+2)
sum[i]=sum2[i]=sum3[i]=sum4[i]=0;
s[1]=' '+s[1];
s[2]=' '+s[2];
forl(j,1,2)
forl(i,1,n)
pd&=s[j][i]=='x';
forl(i,1,n)
sum[i]|=s[1][i]=='.',sum2[i]=sum[i];
forl(i,1,n)
sum[i]|=sum[i-1];
forr(i,n,1)
sum2[i]|=sum2[i+1];
forl(i,1,n)
sum3[i]|=s[2][i]=='.',sum4[i]=sum3[i];
forl(i,1,n)
sum3[i]|=sum3[i-1];
forr(i,n,1)
sum4[i]|=sum4[i+1];
if(pd==1)
{
cout<<0<<endl;
return ;
}
ll ans=0;
forl(i,1,n)
if(s[2][i-1]=='x' && s[2][i]=='.' && s[2][i+1]=='x' && (sum[i-1] || sum3[i-2]) && (sum2[i+1] || sum4[i+2]))
ans++;
forl(i,1,n)
if(s[1][i-1]=='x' && s[1][i]=='.' && s[1][i+1]=='x' && (sum[i-2] || sum3[i-1]) && (sum2[i+2] || sum4[i+1]))
ans++;
cout<<ans<<endl;
}
void init(){}
int main()
{
IOS;
_t_=1;
cin>>_t_;
while(_t_--)
solve();
QwQ;
}
D
题目链接
CF1997D Maximize the Root (codeforces)
CF1997D Maximize the Root (luogu)
解题思路
二分答案。
可以逐一计算每个节点在节点一最终的权值为
代价的转移比较显然。
时间复杂度
注意下传代价时可能会爆 long long
,记得及时剪枝。
参考代码
点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
打 cf 不要用 umap!!!
记住,rating 是身外之物。
该冲正解时冲正解!
Problem:
算法:
思路:
*/
#include<bits/stdc++.h>
using namespace std;
//#define map unordered_map
#define re register
#define ll long long
#define forl(i,a,b) for(re ll i=a;i<=b;i++)
#define forr(i,a,b) for(re ll i=a;i>=b;i--)
#define forll(i,a,b,c) for(re ll i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(re ll i=a;i>=b;i-=c)
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);init();
#define endl '\n'
#define QwQ return 0;
#define db long double
#define ull unsigned long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
#define x first
#define y second
#define aty cout<<"Yes\n";
#define atn cout<<"No\n";
#define cfy cout<<"YES\n";
#define cfn cout<<"NO\n";
#define xxy cout<<"yes\n";
#define xxn cout<<"no\n";
#define printcf(x) x?cout<<"YES\n":cout<<"NO\n";
#define printat(x) x?cout<<"Yes\n":cout<<"No\n";
#define printxx(x) x?cout<<"yes\n":cout<<"no\n";
#define maxqueue priority_queue<ll>
#define minqueue priority_queue<ll,vector<ll>,greater<ll>>
void Max(ll&x,ll y){x=max(x,y);}
void Min(ll&x,ll y){x=min(x,y);}
ll _t_;
void _clear(){}
ll n;
ll a[200010];
vector<ll>G[200010];
ll L,R;
ll fl;
ll x,y;
void dfs(ll x,ll fa,ll need)
{
if(need>1e17)
{
fl=0;
return ;
}
ll pd=0;
for(auto i:G[x])
if(i!=fa)
pd=1,dfs(i,x,need+max(0ll,need-a[x]));
// cout<<x<<' '<<fa<<' '<<need;
if(pd==0 && a[x]<need)
{
// need=max(need-a[x],0ll);
fl=0;
}
}
bool check(ll x)
{
fl=1;
for(auto i:G[1])
dfs(i,1,x-a[1]);
return fl;
}
void solve()
{
_clear();
cin>>n;
forl(i,0,n+2)
G[i].clear();
forl(i,1,n)
cin>>a[i];
forl(i,2,n)
cin>>x,G[x].pb(i),G[i].pb(x);
L=0,R=1e10;
while(L<R)
{
ll Mid=(L+R+1)/2;
if(check(Mid))
L=Mid;
else
R=Mid-1;
}
cout<<L<<endl;
}
void init(){}
int main()
{
IOS;
_t_=1;
cin>>_t_;
while(_t_--)
solve();
QwQ;
}
E
upd:原来代码 fst 了,现已修改了代码和思路。
题目链接
解题思路
根号分治。
设阙值为
这里第一个预处理
时间复杂度
参考代码
点击查看代码
// LUOGU_RID: 170011394
#include<bits/stdc++.h>
using namespace std;//
//#define map unordered_map
#define re register
#define ll int
#define forl(i,a,b) for(re ll i=a;i<=b;i++)
#define forr(i,a,b) for(re ll i=a;i>=b;i--)
#define forll(i,a,b,c) for(re ll i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(re ll i=a;i>=b;i-=c)
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);init();
//#define endl '\n'
#define QwQ return 0;
#define db long double
#define ull unsigned long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
#define x first
#define y second
#define aty cout<<"Yes\n";
#define atn cout<<"No\n";
#define cfy cout<<"YES\n";
#define cfn cout<<"NO\n";
#define xxy cout<<"yes\n";
#define xxn cout<<"no\n";
#define printcf(x) x?cout<<"YES\n":cout<<"NO\n";
#define printat(x) x?cout<<"Yes\n":cout<<"No\n";
#define printxx(x) x?cout<<"yes\n":cout<<"no\n";
#define maxqueue priority_queue<ll>
#define minqueue priority_queue<ll,vector<ll>,greater<ll>>
namespace Fread
{
const int SIZE = 1 << 16;
char buf[SIZE], *S, *T;
inline char getchar() { if (S == T) { T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n'; } return *S++; }
}
using namespace Fread;
namespace Fwrite
{
const int SIZE = 1 << 16;
char buf[SIZE], *S = buf, *T = buf + SIZE;
inline void flush() { fwrite(buf, 1, S - buf, stdout); S = buf; }
inline void putchar(char c) { *S++ = c; if (S == T) flush(); }
struct NTR { ~NTR() { flush(); } } ztr;
}
using namespace Fwrite;
#define getchar Fread::getchar
#define putchar Fwrite::putchar
namespace Fastio
{
struct Reader
{
template <typename T> Reader& operator >> (T &x)
{
x = 0;
short f = 1;
char c = getchar();
while (c < '0' || c > '9') { if (c == '-') f *= -1; c = getchar(); }
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= f;
return *this;
}
Reader& operator >> (double &x)
{
x = 0;
double t = 0;
short f = 1, s = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '.') { if (c == '-') f *= -1; c = getchar(); }
while (c >= '0' && c <= '9' && c != '.') x = x * 10 + (c ^ 48), c = getchar();
if (c == '.') c = getchar();
else { x *= f; return *this; }
while (c >= '0' && c <= '9') t = t * 10 + (c ^ 48), s++, c = getchar();
while (s--) t /= 10.0;
x = (x + t) * f;
return *this;
}
Reader& operator >> (long double &x)
{
x = 0;
long double t = 0;
short f = 1, s = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '.') { if (c == '-') f *= -1; c = getchar(); }
while (c >= '0' && c <= '9' && c != '.') x = x * 10 + (c ^ 48), c = getchar();
if (c == '.') c = getchar();
else { x *= f; return *this; }
while (c >= '0' && c <= '9') t = t * 10 + (c ^ 48), s++, c = getchar();
while (s--) t /= 10.0;
x = (x + t) * f;
return *this;
}
Reader& operator >> (__float128 &x)
{
x = 0;
__float128 t = 0;
short f = 1, s = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '.') { if (c == '-') f *= -1; c = getchar(); }
while (c >= '0' && c <= '9' && c != '.') x = x * 10 + (c ^ 48), c = getchar();
if (c == '.') c = getchar();
else { x *= f; return *this; }
while (c >= '0' && c <= '9') t = t * 10 + (c ^ 48), s++, c = getchar();
while (s--) t /= 10.0;
x = (x + t) * f;
return *this;
}
Reader& operator >> (char &c)
{
c = getchar();
while (c == ' ' || c == '\n' || c == '\r') c = getchar();
return *this;
}
Reader& operator >> (char *str)
{
int len = 0;
char c = getchar();
while (c == ' ' || c == '\n' || c == '\r') c = getchar();
while (c != ' ' && c != '\n' && c != '\r') str[len++] = c, c = getchar();
str[len] = '\0';
return *this;
}
Reader& operator >> (string &str)
{
str.clear();
char c = getchar();
while (c == ' ' || c == '\n' || c == '\r') c = getchar();
while (c != ' ' && c != '\n' && c != '\r') str.push_back(c), c = getchar();
return *this;
}
Reader() {}
} cin;
const char endl = '\n';
struct Writer
{
const int Setprecision = 6;
typedef int mxdouble;
template <typename T> Writer& operator << (T x)
{
if (x == 0) { putchar('0'); return *this; }
if (x < 0) putchar('-'), x = -x;
static short sta[40];
short top = 0;
while (x > 0) sta[++top] = x % 10, x /= 10;
while (top > 0) putchar(sta[top] + '0'), top--;
return *this;
}
Writer& operator << (double x)
{
if (x < 0) putchar('-'), x = -x;
mxdouble _ = x;
x -= (double)_;
static short sta[40];
short top = 0;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
if (top == 0) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
putchar('.');
for (int i = 0; i < Setprecision; i++) x *= 10;
_ = x;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
for (int i = 0; i < Setprecision - top; i++) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
return *this;
}
Writer& operator << (long double x)
{
if (x < 0) putchar('-'), x = -x;
mxdouble _ = x;
x -= (long double)_;
static short sta[40];
short top = 0;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
if (top == 0) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
putchar('.');
for (int i = 0; i < Setprecision; i++) x *= 10;
_ = x;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
for (int i = 0; i < Setprecision - top; i++) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
return *this;
}
Writer& operator << (__float128 x)
{
if (x < 0) putchar('-'), x = -x;
mxdouble _ = x;
x -= (__float128)_;
static short sta[40];
short top = 0;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
if (top == 0) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
putchar('.');
for (int i = 0; i < Setprecision; i++) x *= 10;
_ = x;
while (_ > 0) sta[++top] = _ % 10, _ /= 10;
for (int i = 0; i < Setprecision - top; i++) putchar('0');
while (top > 0) putchar(sta[top] + '0'), top--;
return *this;
}
Writer& operator << (char c) { putchar(c); return *this; }
Writer& operator << (char *str)
{
int cur = 0;
while (str[cur]) putchar(str[cur++]);
return *this;
}
Writer& operator << (const char *str)
{
int cur = 0;
while (str[cur]) putchar(str[cur++]);
return *this;
}
Writer& operator << (string str)
{
int st = 0, ed = str.size();
while (st < ed) putchar(str[st++]);
return *this;
}
Writer() {}
} cout;
}
using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
void Max(ll&x,ll y){x=max(x,y);}
void Min(ll&x,ll y){x=min(x,y);}
ll _t_;
void _clear(){}
ll n,q,sq,sq2;
ll a[200010];
//ll vis[200010][320];
bitset<1210>vis[200010];
ll sum[200010][560];
ll maxn[200010],minn[200010],Sum[200010];
ll times;
map<ll,map<ll,ll>>mp;
ll get(ll l,ll r,ll x)
{
ll su=0;
forl(i,l,r)
su+=a[i]>=x,times++;
return su;
}
ll lst;
ll x,y;
void solve()
{
_clear();
cin>>n>>q;
sq=558,sq2=1200;
// sq=sqrt(n);
forl(i,1,n)
{
maxn[i]=1e18;
cin>>a[i];
forl(j,0,sq+1)
{
sum[i][j]=sum[i-1][j];
if(a[i]>=j)
sum[i][j]++;
times++;
}
}
forl(i,1,n)
Sum[i]=Sum[i-1]+(a[i]==200000);
forl(i,1,sq2)
{
ll sum=1,sum2=0;
forl(j,1,n)
{
times++;
if(sum>a[j])
continue;
vis[j][i]=1;
sum2++;
if(sum2==i)
{
sum2=0;
sum++;
}
}
}
while(q--)
{
cin>>x>>y;
if(a[x]==2e5)
{
cfy;
continue;
}
if(a[x]==1 && Sum[x]>y)
{
cfn;
continue;
}
if(maxn[x]<=y)
{
cfy;
continue;
}
if(minn[x]>=y)
{
cfn;
continue;
}
if(a[x]>=(x+y-1)/y)
{
cfy;
lst=1;
continue;
}
if(mp[x][y])
{
if(mp[x][y]==1){
cfy;
}
else
cfn;
continue;
}
if(y<=1200)
{
printcf(vis[x][y]);
continue;
}
ll now=1,sum2=1;
forl(i,1,n)
{
ll L=now+y-1,R=n,fl=1;
while(L<R)
{
ll Mid=(L+R)/2;
if(sum[Mid][sum2]-sum[now-1][sum2]<y)
L=Mid+1;
else
R=Mid;
if(L>=x)
{
if(a[x]>=sum2)
mp[x][y]=1,Min(maxn[x],y);
else
mp[x][y]=-1,Max(minn[x],y);
printcf(a[x]>=sum2);
fl=0;
break;
}
}
if(!fl)
break;
sum2++;
now=L+1;
if(L>=x)
{
if(a[x]>=sum2-1)
mp[x][y]=1,Min(maxn[x],y);
else
mp[x][y]=-1,Max(minn[x],y);
printcf(a[x]>=sum2-1);
break;
}
}
}
}
void init(){}
int main()
{
// IOS;
_t_=1;
// cin>>_t_;
while(_t_--)
solve();
QwQ;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 凌晨三点救火实录:Java内存泄漏的七个神坑,你至少踩过三个!