QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#381921 | #5459. Goose, goose, DUCK? | wsc2008 | WA | 12ms | 58532kb | C++14 | 2.6kb | 2024-04-07 21:59:21 | 2024-04-07 21:59:22 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void write(ll x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
const ll N=1e6+9,V=1e6;
ll n,k,a[N],mn[N<<2],tr[N<<2],tag[N];
vector<ll>vec[N];
struct O{
ll l,r,sgn;
};
vector<O>vq[N];
void Build(ll x,ll l,ll r){
mn[x]=0,tr[x]=r-l+1;
if(l==r)return ;
ll mid=(l+r)>>1;
Build(x<<1,l,mid);
Build(x<<1|1,mid+1,r);
}
void Pushup(ll x){
mn[x]=min(mn[x<<1],mn[x<<1|1]);
tr[x]=0;
if(mn[x]==mn[x<<1])tr[x]+=tr[x<<1];
if(mn[x]==mn[x<<1|1])tr[x]+=tr[x<<1|1];
}
void Pushtag(ll x,ll k){
tag[x]+=k,mn[x]+=k;
}
void Pushdown(ll x){
if(!tag[x])return ;
Pushtag(x<<1,tag[x]);
Pushtag(x<<1|1,tag[x]);
tag[x]=0;
}
void Upd(ll x,ll l,ll r,ll ql,ll qr,ll v){
if(l>qr||r<ql)return ;
if(ql<=l&&r<=qr)return Pushtag(x,v),void();
ll mid=(l+r)>>1;
Pushdown(x);
Upd(x<<1,l,mid,ql,qr,v);
Upd(x<<1|1,mid+1,r,ql,qr,v);
Pushup(x);
}
pii Query(ll x,ll l,ll r,ll ql,ll qr){
if(l>qr||r<ql)return make_pair((ll)1e9,0);
if(ql<=l&&r<=qr)return make_pair(mn[x],tr[x]);
Pushdown(x);
ll mid=(l+r)>>1;
if(qr<=mid)return Query(x<<1,l,mid,ql,qr);
if(ql>mid)return Query(x<<1|1,mid+1,r,ql,qr);
pii L=Query(x<<1,l,mid,ql,qr),R=Query(x<<1|1,mid+1,r,ql,qr);
pii res=make_pair(min(L.first,R.first),0);
if(res.first==L.first)res.second+=L.second;
if(res.first==R.first)res.second+=R.second;
return res;
}
bool Med;
int main(){
cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
n=read(),k=read();
rep(i,1,n)a[i]=read(),vec[a[i]].push_back(i);
rep(i,1,V){
if((ll)vec[i].size()<k)continue;
rep(j,0,(ll)vec[i].size()-k){
ll Lx=(j==0?1:vec[i][j-1]+1);
ll Ly=vec[i][j];
ll Rx=vec[i][j+k-1];
ll Ry=(j+k==(ll)vec[i].size()?n:vec[i][j+k]);
vq[Lx].push_back((O){Rx,Ry,1});
vq[Ly+1].push_back((O){Rx,Ry,-1});
}
}
Build(1,1,n);
ll ans=0;
rep(i,1,n){
for(O o:vq[i])Upd(1,1,n,o.l,o.r,o.sgn);
pii qq=Query(1,1,n,i,n);
if(qq.first==0)ans+=qq.second;
}
write(ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 58168kb
input:
6 2 1 2 2 1 3 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 12ms
memory: 58532kb
input:
6 1 1 2 3 4 5 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 8ms
memory: 58256kb
input:
100 10 142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...
output:
4152
result:
wrong answer 1st numbers differ - expected: '4309', found: '4152'