QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#153343 | #5459. Goose, goose, DUCK? | inverno | WA | 1ms | 30144kb | C++14 | 2.2kb | 2023-08-29 22:36:57 | 2023-08-29 22:36:57 |
Judging History
answer
#include<bits/stdc++.h>
#define lch (w<<1)
#define rch ((w<<1)|1)
using namespace std;
const int N = 1e6+5;
const int INF = N;
int n, k;
int a[N],c[N];
vector<int> b[N];
struct rec{
int val, cnt;
int resi;
}tr[N<<2];
long long ans;
inline rec mymin(rec a, rec b) {
if (a.val != b.val) {
return (a.val < b.val)?a:b;
}
return (rec){a.val,a.cnt+b.cnt};
}
void pushdown(int w, int l, int r){
tr[lch].resi += tr[w].resi;
tr[lch].val += tr[w].resi;
tr[rch].resi += tr[w].resi;
tr[rch].val += tr[w].resi;
tr[w].resi = 0;
return ;
}
void add(int w, int l, int r, int L, int R, int y) {
if (L <= l && r <= R) {
tr[w].val += y;
tr[w].resi += y;
return ;
}
if (tr[w].resi) pushdown(w,l,r);
int mid = (l+r)>>1;
if (L > R) return;
if (L <= mid) add(lch,l,mid,L,R,y);
if (mid < R) add(rch,mid+1,r,L,R,y);
tr[w] = mymin(tr[lch], tr[rch]);
return ;
}
rec query(int w,int l, int r, int L, int R) {
if (L <= l && r <= R) {
return tr[w];
}
if (tr[w].resi) pushdown(w,l,r);
int mid = (l+r)>>1;
rec t1 = (rec){INF,0}, t2 = (rec){INF,0};
if (L>R) return t1;
if (L <= mid) t1 = query(lch,l,mid,L,R);
if (mid < R) t2 = query(rch,mid+1,r,L,R);
return mymin(t1,t2);
}
void build(int w, int l, int r){
int mid = (l+r)>>1;
tr[w] = (rec){0,r-l+1};
if (l>=r) return;
build(lch,l,mid);
build(rch,mid+1,r);
return;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
for (int i = 1;i <= n;++ i) {
cin >> a[i];
b[a[i]].push_back(i);
}
build(1,1,n);
for (int r = 1;r <= n;++ r){
int m = (c[a[r]]++);
if (m >= k - 1) {
vector<int> &tmp = b[a[r]];
if (m == k-1) {
add(1,1,n,1,tmp[0],+1);
}
else {
add(1,1,n,tmp[m-k]+1,tmp[m-k+1],+1);
if (m > k) add(1,1,n,tmp[m-k-1]+1,tmp[m-k],-1);
}
}
rec x = query(1,1,n,1,r);
if (x.val == 0) {
ans = ans + x.cnt;
}
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 30144kb
input:
6 2 1 2 2 1 3 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 1ms
memory: 30028kb
input:
6 1 1 2 3 4 5 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 30076kb
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:
854
result:
wrong answer 1st numbers differ - expected: '4309', found: '854'