QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#714685#5459. Goose, goose, DUCK?WzyCompile Error//C++143.1kb2024-11-06 02:25:222024-11-06 02:25:23

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 02:25:23]
  • 评测
  • [2024-11-06 02:25:22]
  • 提交

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;
    int 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 +=  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);
    pushup(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);
    unordered_map<int,vector<int>> mp;
    unordered_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]+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;
}

詳細信息

answer.code: In function ‘void solve()’:
answer.code:93:28: error: use of deleted function ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<int, int>; _Tp = int; _Hash = std::hash<std::pair<int, int> >; _Pred = std::equal_to<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]’
   93 |     unordered_map<PII,int> id;
      |                            ^~
In file included from /usr/include/c++/13/unordered_map:41,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:188,
                 from answer.code:1:
/usr/include/c++/13/bits/unordered_map.h:148:7: note: ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::pair<int, int>; _Tp = int; _Hash = std::hash<std::pair<int, int> >; _Pred = std::equal_to<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >]’ is implicitly deleted because the default definition would be ill-formed:
  148 |       unordered_map() = default;
      |       ^~~~~~~~~~~~~
/usr/include/c++/13/bits/unordered_map.h:148:7: error: use of deleted function ‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’
In file included from /usr/include/c++/13/bits/unordered_map.h:33:
/usr/include/c++/13/bits/hashtable.h:530:7: note: ‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’ is implicitly deleted because the default definition would be ill-formed:
  530 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/13/bits/hashtable.h:530:7: error: use of deleted function ‘std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’
In file included from /usr/include/c++/13/bits/hashtable.h:35:
/usr/include/c++/13/bits/hashtable_policy.h:1710:7: note: ‘std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::pair<int, int> >; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]’ is implicitly deleted because the default definition would be ill-formed:
 1710 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable_policy.h:1710:7: error: use of deleted function ‘std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::pair<int, int>; _Value = std::pair<const std::pair<int, int>, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::pair<int, int> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]’
/usr/include/c++/13/bits/hashtable_policy.h: In instantiation of ‘std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<std::pair<int, int> >]’:
/usr/include/c++/13/bits/hashtable_policy.h:1297:7:   required from here
/usr/include/c++/13/bits/hashtable_policy.h:1214:49: error: use of deleted function ‘std::hash<std::pair<int, int> >::hash()’
 1214 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                   ...