//建议这种滑动窗口的题用队列实现,而不用原始的双指针实现,这样会简单很多不容易出错,其本质都是一样的
感觉不如原始双指针()
https://ac.nowcoder.com/acm/contest/99277/D
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define int long long
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'
typedef pair<int,int> PII;
int n,k,cnt0,cnt1,res;
string s;
void solve(){
cin>>n>>k;
cin>>s;
for(int i=0,j=0;i<s.size();i++){
if(s[i]=='0')cnt0++;
else res+=cnt0,cnt1++;
while(res>k){
if(s[j]=='0')res-=cnt1,cnt0--;
else cnt1--;
j++;
}
if(res==k){
cout<<j+1<<" "<<i+1;
return;
}
}
cout<<-1;
}
signed main(){
FAST
int T=1;
//cin>>T;
while(T--){
solve();
}
return 0;
}
https://www.acwing.com/problem/content/469/
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define int long long
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'
typedef pair<int,int> PII;
int n,t,k,res;
queue<PII>q;//时间 国籍
int a[N],f[N];
void solve(){
cin>>n;
for(int i=0;i<n;i++){
cin>>t>>k;
//先加进来
for(int j=0;j<k;j++){
int tt;
cin>>tt;
if(!f[tt])res++;
f[tt]++;
q.push(make_pair(t,tt));
}
//从前面踢
auto c=q.front();
while(t-(c.first)>=86400){
f[c.second]--;
if(!f[c.second])res--;
q.pop();
c=q.front();
}
cout<<res<<endl;
}
}
signed main(){
FAST
int T=1;
//cin>>T;
while(T--){
solve();
}
return 0;
}