QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#714673 | #5459. Goose, goose, DUCK? | Wzy | WA | 0ms | 3800kb | C++14 | 3.0kb | 2024-11-06 02:13:50 | 2024-11-06 02:13:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=1e6+10,M=1e6+10;
const int mod=1e9+7;
int INF = 1e9;
int n, m;
int w[N];
struct Node
{
int l, r;
LL sum,mn, add;
void operator += (Node t){
int tmp;
tmp=min(mn,t.mn);
if(tmp!=mn) sum=0;
if(tmp==t.mn) sum+=t.sum;
mn=tmp;
}
}tr[N * 4];
void pushup(int u)
{ tr[u].sum=0;
tr[u].mn =min( tr[u << 1].mn , tr[u << 1 | 1].mn);
if(tr[u].mn==tr[u << 1].mn) tr[u].sum+=tr[u << 1].sum;
if(tr[u].mn==tr[u << 1 | 1].mn) tr[u].sum+=tr[u << 1 | 1].sum;
}
void pushdown(int u)
{
auto &root = tr[u], &left = tr[u << 1], &right = tr[u << 1 | 1];
if (root.add)
{
left.add += root.add, left.mn += root.add;
right.add += root.add, right.mn += root.add;
root.add = 0;
}
}
void build(int u, int l, int r)
{
if (l == r) tr[u] = {l, r, 1, 0, 0};
else
{
tr[u] = {l, r};
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
//cout<<l<<" "<<r<<" "<<tr[u].sum<<endl;
}
void modify(int u, int l, int r, int d)
{
if (tr[u].l >= l && tr[u].r <= r)
{
tr[u].mn += (LL) d;
tr[u].add += d;
}
else // 一定要分裂
{
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
if (l <= mid) modify(u << 1, l, r, d);
if (r > mid) modify(u << 1 | 1, l, r, d);
pushup(u);
}
}
Node query(int u, int l, int r)
{
if (tr[u].l >= l && tr[u].r <= r) return tr[u];
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
Node res={0,0,0,INF,0};
if (l <= mid) res = query(u << 1, l, r);
if (r > mid) res += query(u << 1 | 1, l, r);
return res;
}
void solve(){
int n,k;
cin>>n>>k;
vector<int> a(n);
map<int,vector<int>> mp;
map<PII,int> id;
build(1,0,n);
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++){
mp[a[i]].push_back(i);
}
for(auto [x,y]:mp){
for(int j=0;j<y.size();j++) id[{x,y[j]}]=j;
}
LL res=0;
//cout<<tr[1].sum<<endl;
for(int i=0;i<n;i++){
if(id.count({a[i],i})){
int t=id[{a[i],i}];
if(t==k-1){
modify(1,0,mp[a[i]][t-k+1],1);
}
else if(t==k){
modify(1,0,mp[a[i]][0],-1);
modify(1,mp[a[i]][0]+1,mp[a[i]][1],1);
}
else if(t>k){
modify(1,mp[a[i]][t-k-1],mp[a[i]][t-k],-1);
modify(1,mp[a[i]][t-k]+1,mp[a[i]][t-k+1],1);
}
}
Node tmp=query(1,0,i);
//cout<<i<<" "<<tmp.mn<<" "<<tmp.sum<<endl;
if(tmp.mn==0) res+=tmp.sum;
}
//cout<<endl;
cout<<res<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
//cin>>T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
6 2 1 2 2 1 3 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
6 1 1 2 3 4 5 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3800kb
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:
338
result:
wrong answer 1st numbers differ - expected: '4309', found: '338'